How do I remember session of @abacritt/angularx-social-login after refresh

652 Views Asked by At

On angular using the package:
@abacritt/angularx-social-login

I am using version 2.0.0.

After successfully login in once using google login provider, I would like the browser to remember the login after refreshing or closing the browser.

I want to do it client side only. (unless it's not secure like that?)

I am guessing I should save the token as cookie on the browser or on local storage.
I am just not sure how to do it.

This is what I currently do:

import { SocialAuthService, SocialUser } from '@abacritt/angularx-social-login';

@Injectable({ providedIn: 'root' })
export class AuthService {
  public user: SocialUser;
  public loggedIn = false;

  constructor(private authService: SocialAuthService) {
    this.authService.authState.subscribe(async (user) => {
      this.user = user;
      this.loggedIn = user != null;
    });
  }
}

Which is just getting the user logged into.

1

There are 1 best solutions below

0
Minux-Dev On

I know it's a newbie answer but this is how I did it

  ngOnInit() {
    this.authService.authState.subscribe((user) => {
      this.user = user;
      this.loggedIn = user != null;
      localStorage.setItem('id_token', user.idToken);
    }); 
   }