DEV Community

DEBOS DAS
DEBOS DAS

Posted on

jwt decode link: https://www.npmjs.com/package/jwt-decode

npm i jwt-decode

  1. verifyJwt.ts****
    import { jwtDecode } from 'jwt-decode';
    export const verifyToken = (token: string) => {
    return jwtDecode(token);
    };

  2. Login.tsx****
    const onSubmit = async (data) => {
    console.log(data);
    const userInfo = {
    id: data.id,
    password: data.password,
    };
    const res = await login(userInfo).unwrap();
    const user = verifyToken(res.data.accessToken);
    dispatch(setUser({ user: user, token: res.data.accessToken }));
    };

Top comments (0)