Reputation: 65
I am in a project in Angular 4 in which, after login, I need to avoid that when the user refreshes the page (F5), log out of the system. Is there any parameter I can change to avoid this behavior?
Upvotes: 0
Views: 4265
Reputation: 1413
What you're looking for is called session management. A simplistic approach would be writing an object to localstorage, sessionstorage, or a cookie that you can check to see if a client is logged in, preferably with a timestamp that you can check to force them to re-login if they haven't logged in over a specific interval. Note that this not a secure approach.
A more in depth approach would be using something like JWT though this isn't always suggested.
Either way, with Angular 4, you'll validate that a user is logged in (typically with a route guard), and if they are, the user will no longer be logged out after refreshing the page. If not, the route guard will redirect the user to the login page/component
See here or here for a video guide of how to approach session management with Angular.
Upvotes: 4