Oscar
Oscar

Reputation: 241

JWT API token storage

I'm writing the API part of an application and am working on the authentication using JWT. I'm now simply generating a token and when the user is created sending the token back in a json object for the front-end to deal with. But is this correct? Shouldn't I put the token into the header on the back-end side? Since when I want to log out the user I want to access the token in the header and delete it from the back-end side...

Thankful for any response

Upvotes: 3

Views: 144

Answers (1)

Ishwar
Ishwar

Reputation: 6201

You can use cookies to store the JWT, When the JWT token is stored in a cookie, the browser will automatically send it along with each request to the same domain.

If you are using nodejs, The best way to store JWT token in cookie-session

Advantage of cookie-session: cookie-session variable do not delete while restarting server or doing modifications on code

Upvotes: 1

Related Questions