本文整理汇总了TypeScript中angular2-social-login.AuthService类的典型用法代码示例。如果您正苦于以下问题:TypeScript AuthService类的具体用法?TypeScript AuthService怎么用?TypeScript AuthService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AuthService类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: callback
/**
* Authenticate the user in google
*/
gauth(callback) {
this._auth.login('google').subscribe((data) => {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
this.http.post('/api/auth/login', data, { headers: headers })
.map(res => res.json())
.subscribe(r => {
if (r.success) {
let profile = {
email: data['email'],
image: data['image'],
name: data['name'],
id: r.id
};
// Save profile and token to local storage
localStorage.setItem('token', data['token']);
localStorage.setItem('profile', JSON.stringify(profile));
return callback(null, profile);
} else {
return callback(r.message);
}
});
});
}
示例2:
logout(){
this._auth.logout().subscribe(
(data)=>{
this.cookieService.removeAll();
this._router.navigate(['/login']);
console.log(data);this.user=null;
}
)
}
示例3: logout
logout(): void {
// clear token remove user from local storage to log user out
this.token = null;
localStorage.removeItem('currentUser');
if (localStorage.getItem('_login_provider')) {
this._auth.logout().subscribe(
(data) => {
}
)
}
}
示例4: logout
/**
* Log out the user
*/
logout(callback) {
let error: any;
let instance = JSON.parse(localStorage.getItem('instance'));
this._auth.logout().subscribe((data) => {
if (data) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
let email = this.getProfile().email;
this.http.post('/api/auth/logout', email, { headers: headers })
.map(res => res.json())
.subscribe(data => {
if (data.success) {
this.clearLocalStorage();
callback(null);
} else {
callback(data.message);
}
})
}
});
}
示例5: signIn
signIn(provider) {
this.sub = this._auth.login(provider)
.map(data => {
console.log(data);
this.ret = this.dbConnectService.post('usuarios', 'loginSocial', {
user: data['email'],
token_social: data['token'],
provider: data['provider']
}).map((response: Response) => {
let ret = {
existe: (response['user'].nombre != null),
nombre: data['name'],
email: data['email'],
provider: data['provider']
};
return ret;
}).catch((err: Response, caught: Observable<any>) => {
return Observable.throw(err);
});
return this.ret;
// this.ret.subscribe(response=> {
// console.log(response);
// if (response == undefined) {
// Observable.throw({error: 'Usuario no encontrado, por favor registrese'});
// this.logout();
// return false;
// }
// this.persistLogin(response);
// });
}).share();
return this.sub;
}