使用角度4 Web应用程序使用谷歌和Facebook的社交登录

时间:2017-10-27 07:02:19

标签: angular

我使用google为我的angular 4 web应用程序开发了一个使用ng4-social-login库的社交登录。

在这里,我可以使用谷歌帐户登录,但我遇到登出问题。

以下是我的代码示例

app.module.ts

import {
  SocialLoginModule, 
  AuthServiceConfig,
  GoogleLoginProvider, 

 } from 'ng4-social-login';

const CONFIG = new AuthServiceConfig([

  {

    id: GoogleLoginProvider.PROVIDER_ID,

    provider: new GoogleLoginProvider('630575313920-5a2ff6ft82obionc2gs3se9fl111bsqh.apps.googleusercontent.com')
  },


]);

export function provideConfig() {

  return CONFIG;

}

 @NgModule({

  declarations: [

    AppComponent,

    LoginSignupComponent,

    HomeComponent,


  ],

  imports: [

    BrowserModule,

    FormsModule,

    HttpModule,      

    SocialLoginModule
  ],

  providers: [LoginSignupService,ForgotPasswordService,AuthGuard,ResetPasswordService,
      **{
          provide: AuthServiceConfig,
          useFactory: provideConfig
      }**  
  ],

  bootstrap: [AppComponent]

})

export class AppModule { }

login.component.ts 这是登录工作正常

import { 
  AuthService, 
  FacebookLoginProvider, 
  GoogleLoginProvider,
  LinkedinLoginProvider,
  SocialUser
} from 'ng4-social-login';

**export class LoginSignupComponent implements OnInit {**

private user: SocialUser;

private loggedIn: boolean;

 constructor(private authService: AuthService){}

ngOnInit() {

   this.authService.authState.subscribe((user) => {

      this.user = user;
      this.loggedIn = (user != null);      

          if(this.user != null){           
            localStorage.removeItem('loggedOut');
           this.signupService.gmailLogin(user);
          this.router.navigate(['home']);
        }         
    });
   }

signInWithGoogle(): void {

    this.authService.signIn(GoogleLoginProvider.PROVIDER_ID);

  }

**}**

当我点击退出按钮时,使用以下方法从Google帐户退出

home.component.ts

import { AuthService} from 'ng4-social-login';

constructor(private authService: AuthService){}

gmailLogOut(){

   **this.authService.signOut();**   


}

但是上面这个方法给我以下错误并且没有退出谷歌帐户,

ERROR Error: Uncaught (in promise): Login provider not found
at resolvePromise (zone.js:783)
at zone.js:709
at ng4-social-login.umd.js:88
at new ZoneAwarePromise (zone.js:847)
at AuthService.webpackJsonp.../../../../ng4-social-login/ng4-social-login.umd.js.AuthService.signOut (ng4-social-login.umd.js:75)
at HomeComponent.webpackJsonp.../../../../../src/app/home/home.component.ts.HomeComponent.gmailLogOut (home.component.ts:50)
at Object.eval [as handleEvent] (HomeComponent.html:44)
at handleEvent (core.es5.js:11997)
at callWithDebugContext (core.es5.js:13458)
at Object.debugHandleEvent [as handleEvent] (core.es5.js:13046)

任何人都可以帮助我。谢谢。

0 个答案:

没有答案