3

I have a ReactJS project that when I log in I save my token to local storage. How can I convert the token JWT to ab object and get id-user?

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwiZW1haWwiOiJhZG1pbkBnbWFpbC5jb20iLCJhdXRob3JpemF0aW9uIjoib3duZXIiLCJpYXQiOjE2NTQ5NDkxMjksImV4cCI6MTY1NDk1MjcyOX0.5e-KzJ0Rv3iWmY5MFtEGjRXZBJNlddiZ97X8pHJD03g

decoded

0

2 Answers 2

2

You can also use basic JavaScript to decode it:

const object = JSON.parse(atob(token.split('.')[1]))
Sign up to request clarification or add additional context in comments.

2 Comments

Please refrain from answering such obvious duplicates and mark as duplicate instead
Besides, atob uses standard base64 whereas JWT uses base64url. So this may even throw an exception ...
-1

You can follow this code. enter image description here

1 Comment

Please post code and not pictures of code. Furthermore, if your code refers to an external library, you should at least mention which ...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.