This content originally appeared on DEV Community and was authored by DEBOS DAS
npm i jwt-decode
verifyJwt.ts****
import { jwtDecode } from 'jwt-decode';
export const verifyToken = (token: string) => {
return jwtDecode(token);
};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 }));
};
This content originally appeared on DEV Community and was authored by DEBOS DAS

DEBOS DAS | Sciencx (2024-07-06T18:58:52+00:00) jwt decode link: https://www.npmjs.com/package/jwt-decode. Retrieved from https://www.scien.cx/2024/07/06/jwt-decode-link-https-www-npmjs-com-package-jwt-decode/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.