Managing admin privileges on my website has been challenging. I store user information, including their email and admin status, in a MongoDB database. To determine if a user is an admin, I need to retrieve this information from my Python Flask API using the getUser() function. However, chaining calls between Auth0 login responses and fetching user data has proven difficult for me.
In my web.service.ts file:
getUser(email) {
return this.http.get('http://localhost:5000/api/v1.0/user/' + email).subscribe(resp => {
this.user_info = resp;
});
}
In my home.component.ts file:
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
}
}); //Once this async call is completed, I aim to pass the user_email into the getUser() function and set the isAdmin variable based on the response.
}