【发布时间】:2018-01-15 21:51:34
【问题描述】:
我是 Angular js 的新手。我正在开发一个版本 2 的 Angular 项目。 我已经按照https://www.npmjs.com/package/angular2-social-login 使用angular2-social-login 实现了google auth login。 谷歌登录工作正常,但是当我点击登录按钮退出后,我仍然得到以前登录的用户详细信息,并且没有显示谷歌身份验证登录页面。 这是我的实现细节。
安装 通过 npm
npm install angular2-social-login --save
将 angular2-social-login 添加到您的项目中 在您的 systemjs.config 中添加 angular2-social-login 的地图
'angular2-social-login': 'node_modules/angular2-social-login/dist/bundles/angular2-social-login.min.js'
主模块配置
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';
import { Angular2SocialLoginModule } from "angular2-social-login";
let providers = {
"google": {
"clientId": "GOOGLE_CLIENT_ID"
},
"linkedin": {
"clientId": "LINKEDIN_CLIENT_ID"
},
"facebook": {
"clientId": "FACEBOOK_CLIENT_ID",
"apiVersion": "<version>" //like v2.4
}
};
@NgModule({
imports: [
BrowserModule,
Angular2SocialLoginModule
],
declarations: [AppComponent],
bootstrap: [ AppComponent ]
})
export class AppModule {
constructor(){}
}
Angular2SocialLoginModule.loadProvidersScripts(providers);
login() 和 logout() 的组件配置: 对于 login(provider: string) 提供者是必需的,它应该是任何人(区分大小写)“facebook”、“google”、“linkedin”。
...
import { AuthService } from "angular2-social-login";
...
@Component({
...
})
export class AppComponent implements OnDestroy {
...
constructor(public _auth: AuthService){ }
signIn(provider){
this.sub = this._auth.login(provider).subscribe(
(data) => {
console.log(data);
//user data
//name, image, uid, provider, uid, email, token (accessToken for Facebook & google, no token for linkedIn), idToken(only for google)
}
)
}
logout(){
this._auth.logout().subscribe(
(data)=>{//return a boolean value.}
)
}
...
}
提前谢谢。
【问题讨论】:
-
完成登录后做一个
unsubscribe -
你能澄清一下
-
this.sub.unsubscribe 因为它得到了一个 observable
-
不幸的是它对我不起作用。
标签: angular