Auth0 Home Blog Docs

Getting user_metadata with auth0-spa-js?

I have a MEAN stack application (Angular 8)

I used this tutorial as an authentication model and it works great: https://auth0.com/docs/quickstart/spa/angular2

However, I now need to access user_metadata and app_metadata so from what I can tell that requires accessing the Management API.

Does the spa-js not have a way of doing this natively? Do I need to redo my application auth to use NodeJS apis instead? I feel like if there’s a way to do it, it would be in the getUser function

getUser$(options?): Observable {
return this.auth0Client$.pipe(
concatMap((client: Auth0Client) => from(client.getUser(options))),
tap(user => this.userProfileSubject$.next(user))
);
}

If I have to rebuild, what method should I do? Would it be the “Regular Web App” using Express to handle the auth?

It’s just that using the Auth Service and AuthGuards works so well I really don’t want to have to refactor everything.

Thanks!

1 Like

So, I found i was able to get the roles if I hit the v2 api:
mysite.auth0.com/api/v2/users/[user id]/roles

However, it required a BearerToken that expires.

Looking at this page, it seems like I have to make a post everytime I need to get this token?

Is this really going to generate a new token everytime someone hits the page?

I’m using Angular and it is getting really frustrating because it seems like this is all node based and not actually SPA based. Do I need to redo my application’s authentication in order to work with Auth0? I want to use the auth0-spa-js because it seems like that’s what its written for.

This seems like a serious hurdle to overcome if I have to implement my own node api backend for these types of calls.