abacritt / angularx-social-login

Social login and authentication module for Angular 17
630 stars 388 forks source link

Persist session after refresh #741

Open godtierbatuhan99 opened 6 months ago

godtierbatuhan99 commented 6 months ago

Any idea how to persist the user's session after a googe LOGIN? From google we receive apparently an id_token... tried saving that in local storage but it has no effect. A silent authentication doensn't really work as well...

VictorZakharov commented 6 months ago

Also it's interesting that the demo page can log in automatically, but having the same code in my app needs to click the button. I don't understand why the behavior is different.

lwestfall commented 6 months ago

I duplicated this issue by accident in #747. I'll close and track here instead.

GoogleLoginProvider should persist the token(s?) to localStorage, and try to get them on initialize so it can instantiate _socialUser when present.

The issue is that on browser refresh for a signed-in user, _socialUser will always be null unless the user signs back in (even if we persist the token outside of the provider). This defeats any possibility of refreshing the token after a refresh (which itself seems broken, see #745)

I can attempt a PR this week.

Details to work out (some are notes to self):

sscots commented 4 months ago

+1 My issue is that if a user goes directly to a protected page, then I don't want to redirect them to a login page.

So I have a canActivate waiting on authState. If they aren't logged in, authState returns null 1 time. If they are logged in, it returns null 1st then the social user 2nd. How do I know if authState is going to return once or twice?