I have an Angular app with 2 main components: login and home. After the user logs in, it's redirected to home component. What I want to do is to redirect back to login page if the browser is refreshed. How could I do this? I know hot to redirect to login page, but I don't know how to do it after browser refresh. I have tried some of this solutions, but with not much success. My project is running using: Angular CLI: 12.2.5, Node: 14.17.6.
Asked
Active
Viewed 138 times
0
-
So basically it sounds like the login session should only be valid the first time it loads into the home page. You could probably just remove that session cookie after the home page loads? – Roman Feb 13 '23 at 15:18
-
The logged in user has a name and a role (admin, operator, etc). The ;problem is that after the home page is refreshed, I loose user's name and role. The role disables some buttons from home page. – Ionut Feb 13 '23 at 15:21
-
Ah, I see. This might might help:\ https://stackoverflow.com/questions/5004978/check-if-page-gets-reloaded-or-refreshed-in-javascript/53307588#53307588 Also, Idk about angular, but in RoR, you can choose to just render a specific page after a user goes through the login method without redirecting anywhere. So on refresh, the login info wont be there and you can render the login page again – Roman Feb 13 '23 at 15:32