How to handle jwt token and refreshtoken in a client side express application?

Hey guys i have two express applications,
one is the backend where im having a rest api for all crud operations to the db.

The Client is also structured in a seperate express application were I only do GET requests, there im working with templates to consume data from the rest api.

The way of login is a fetch request at the html template file, included in a script tag below of this file, because i have to set an EventListener to the login submit button and have to extract the username and password, if the login was successful i store the token into localstorage and the refreshtoken into a cookie.

The problem is now i need the token also in the nodejs/express side to call the api and render some other data into the views but from nodejs/express i dont have access to the browsers localstorage.

What can i do here, what is the right way for handeling such a case?
Thank you for any help!

18 thoughts on “How to handle jwt token and refreshtoken in a client side express application?”

  1. In this scenario, you can do one more API call with to the server with accessToken(after successfully login) from that call get the user data and store it in local storage in the browser.

    I hope this helps for you.


Leave a Comment