Irshad Khan
Irshad Khan

Reputation: 31

How to pass JWT token on client side?

I have 2 pages. One page is for registration and the second is for User detail. On the registration page, the user will enter his details and register. My problem is after registration I want to redirect the user to the detail page where only registered users can see their information.

I am using JWT for authentication. After registration when I receive token I do not know how to pass it on to the next page. I want to set a header for the token. but after receiving token when I set header then this header lost when I redirect on next page. I am not sending any ajax request and also I am using simple html and hbs for template engine.

Upvotes: 0

Views: 823

Answers (2)

ArUn
ArUn

Reputation: 1337

If you are not working on REST APIs, you can use the session for the authentication of the user.

So that everything will be handled in the backend. Passport is a good package for handling the user authentication.

Upvotes: 1

Thusithz
Thusithz

Reputation: 884

  • Once you get token from server side keep that in cookies or local storage in browser with time out.
  • Next create common method for read token from local storage or coockies then amend that token into request headers using Interceptor for all ajax calls

Note: Go through about Interceptors

Upvotes: 1

Related Questions