2

我是 Angular 的新手,目前正在实施 Google 登录(OAuth)。每当我使用 Google 进行身份验证时,都会遇到此问题。分享我的登录和注销功能。当前使用 Angular 社交登录,即 Google 登录。

signInWithGoogle(): void {
    this.authService.signIn(GoogleLoginProvider.PROVIDER_ID).then((data) => {
      console.log(data);
    }).catch(data => {
      this.authService.signOut();
      this.router.navigate(['login']);
    });
signOut(): void {
    this.authService.signOut().then((data) => {
      this.router.navigate(['login']);
    }).catch((data) => {
    });
  }
4

1 回答 1

0

这对我有用。

 googleLoginOptions = {
  scope: 'profile email'
}; // https://developers.google.com/api-client-library/javascript/reference/referencedocs#gapiauth2clientconfig

  

signInWithGoogle(): void {
    this.authService.signIn(GoogleLoginProvider.PROVIDER_ID, this.googleLoginOptions ).then((data) => {
      console.log(data);
    }).catch(data => {
      this.authService.signOut();
      this.router.navigate(['login']);
    });

参考:https ://www.npmjs.com/package/angularx-social-login

于 2021-06-18T21:43:30.563 回答