2

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

Timothy G.
  • 6,335
  • 7
  • 30
  • 46

2 Answers2

1

You can also use basic JavaScript to decode it:

const object = JSON.parse(atob(token.split('.')[1]))
phry
  • 35,762
  • 5
  • 67
  • 81
-1

You can follow this code. enter image description here

ghostCommander
  • 366
  • 2
  • 7
  • Please post code and not pictures of code. Furthermore, if your code refers to an external library, you should at least mention which ... – derpirscher Jun 11 '22 at 13:58