I'm using JS client-side and Flask server-side. I have a login page that uses Flask-JWT as the security. After I send the credentials to my server and receive the JWT, I save it in localStorage. How do I then redirect to a page that is protected and needs the token? Can I still change window.location.href to redirect to a different page (within the same domain)? Or do I need to do something server-side? I'm really new to this; any help is appreciated!
Asked
Active
Viewed 277 times
1 Answers
0
One possible solution is after receiving the JWT token and storing in local-storage you will redirect the user to protected page from frontend side using window.location.replace('URL_STRING').
Now on protected page, make sure if token does not exists in local-storage you will redirected the user to the login page so that a user without authentication will not be able to land on protected page.
And on logout you will delete the JWT token from local-storage to destroy the session from front-end application.

samee
- 537
- 2
- 9
-
It's in local storage, but how does the new page know to look at local storage for the auth code upon redirect – Hackerman Aug 07 '18 at 21:55