Best practices regarding querying authentication information multiple times

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.

Hi @evert ,

If you’re using our Angular SDK, this should be caching the user profile from the initial login’s returned ID token, into the auth.user object, so fetching the information multiple times across your app shouldn’t trigger any additional network traffic to Auth0 when using auth.user like the below quickstart section:


This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.