【发布时间】:2020-04-12 23:01:09
【问题描述】:
我有一个使用 Auth0 的站点,为了确定用户是否是管理员,我在我的 mongoDB 数据库中为该用户存储了一个字段,并附有他们的关联电子邮件,我在 getUser() 函数中从我的 python 烧瓶 API 端点读回了这些电子邮件.当用户登录时,我收到 Auth0 用户电子邮件的响应并将相关字段传递到 getUser() 函数,但是,我无法想出一个链接这些调用的解决方案。到目前为止,我已经尝试过使用承诺和订阅,但无济于事。
web.service.ts
getUser(email) {
return this.http.get('http://localhost:5000/api/v1.0/user/' + email).subscribe(resp => {
this.user_info = resp;
});
}
home.component.ts
export class HomeComponent {
constructor(private authService: AuthService,
private webService: WebService) {}
user_email;
is_admin;
ngOnInit() {
this.authService.userProfile$.subscribe(resp => {
if (resp != null) {
this.user_email = resp.email
}
}); //after this aync call is completed, I want to pass the user_email into the getUser()
//function and set is_admin depending on the response
}
【问题讨论】:
标签: angular typescript auth0