I have successfully implemented auth0 into my Angular SPA, but for the UX I have to query at multiple places the user information to hide/show some user elements. For example, a user with the role ‘admin’ is allowed to delete rows from a list, so then I show a delete button.
I have created a wrapper class which returns for example the user information. Example code (‘User’ is my own interface class):
public get userInfo$(): Observable<User> {
return this._auth.user$.pipe(map(u => {
var roles = u?.["<mynamespace url>"]["roles"];
return {
name : u?.name,
email: u?.email,
roles: roles
} as User
}));
}
Now I wonder if I need to optimize/cache this kind of code or is it no problem to call this code multiple times.