我如何使用 ng-angular-social-login 从另一个组件注销 google
HOw can I logout from google from another component using ng-angular-social-login
我正在使用 angularx-social-login。我可以在 loginComponent 中使用 Google 登录:
this.authService.signIn(GoogleLoginProvider.PROVIDER_ID).then(
data => {
this.socialUser = data;
})
我有这样的结构:
app
auth
loginComponent
shared
menuComponent(here is the link logout)
当我尝试从 menuComponent 注销时出现错误:您尚未登录。
logout(): void {
this.authSocialService.signOut()
.then( res => console.log( res ) )
.catch( err => console.log(err) )
}
我的问题是如何从在 loginComponent 中打开的会话的 menuComponent 注销?
Here 重新创建了 Stackblitz 中的错误。
要发出注销,只需从任何组件中的服务调用 signOut() 即可,但请确保先导入 SocialAuthService。这是一个例子。
import { SocialAuthService, GoogleLoginProvider, SocialUser } from 'angularx-social-login';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
user: SocialUser;
constructor(private authService: SocialAuthService) {}
ngOnInit() {
this.authService.authState.subscribe((user) => {
this.user = user;
console.log(user);
});
}
signOut(): void {
this.authService.signOut();
}
}
我正在使用 angularx-social-login。我可以在 loginComponent 中使用 Google 登录:
this.authService.signIn(GoogleLoginProvider.PROVIDER_ID).then(
data => {
this.socialUser = data;
})
我有这样的结构:
app
auth
loginComponent
shared
menuComponent(here is the link logout)
当我尝试从 menuComponent 注销时出现错误:您尚未登录。
logout(): void {
this.authSocialService.signOut()
.then( res => console.log( res ) )
.catch( err => console.log(err) )
}
我的问题是如何从在 loginComponent 中打开的会话的 menuComponent 注销?
Here 重新创建了 Stackblitz 中的错误。
要发出注销,只需从任何组件中的服务调用 signOut() 即可,但请确保先导入 SocialAuthService。这是一个例子。
import { SocialAuthService, GoogleLoginProvider, SocialUser } from 'angularx-social-login';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
user: SocialUser;
constructor(private authService: SocialAuthService) {}
ngOnInit() {
this.authService.authState.subscribe((user) => {
this.user = user;
console.log(user);
});
}
signOut(): void {
this.authService.signOut();
}
}