I am working on an app which has authentication implemented using Node JS, JWT and Sequelize for the API. I'm using React JS / redux on frontend. I've successfully implemented the login/logout/register parts of the application, but now I need access to the current_user which logged in.
I've put JWT in the localStorage, but I want to have access to the user ID, user email, user name and more information about my user currently being logged in.
Should I use cookies? LocalStorage? Or should I create a currentUser method in my API?
I'm a bit lost with this, someone please help me find some useful resources or advices!
Thanks!
Storing the token in LocalStorage is fine. If you need to fetch the user details, create an endpoint in your API such as getUser
. You can then use jwt.decode(accessToken, JWT SECRET HERE)
and return the decoded value (which will be your user) assuming the accessToken is valid.