angularx-social-login icon indicating copy to clipboard operation
angularx-social-login copied to clipboard

State persistent after page refersh

Open Nikhil-Wagh opened this issue 9 months ago • 1 comments

The user state is lost when I refresh the page. The user is logged out and is again required to complete the login flow.

How to avoid this?

Nikhil-Wagh avatar May 03 '24 17:05 Nikhil-Wagh

I have the same issue. I could workaround this by saving the id and the token to a cookie each in the subscription to the authState. Once I have them in cookies, I just add the jwt as Bearer to every message I have to my server and it is authenticated. And also connected everything related to my state with these cookies instead of a variable in the memory.

this way your FE session stays, after refreshing the page the variable gets nulled out, but you have everything you need amongst your cookies (or localStorage, depending on where do you store the user data)

I have another problem with this solution though I couldn't find a solution for: I cannot call refreshAuthToken() after a page refresh, as socialLoginService doesn't use my cookies, but the cleared variable, and it causes a nullptr exception in the social-login library code.... also when I don't do any refresh but call refreshAuthToken() it sets the same jwt as before, so I cannot extend the expiration date.

zooli123 avatar May 13 '24 11:05 zooli123