Angular SDK Subscribe crash

Please include the following information in your post:

  • Which SDK this is regarding: Angular SDK
  • SDK Version: @auth0/auth0-angular": “^1.3.2”
  • Platform Version: Node v14.16.0

When i try to subscribe and get the user profile, its making a bunch of the authentication calls. I just want to make one and based on the app_metadata returned, redirect my user to the appropriate route. Below is the code that I have. Any suggestions:

   this.authService.user$.subscribe((data) => {
         user => {
          this.profile = user
            this.companyId = this.profile.app_metadata.companyId

      this.router.navigate(["my-client", this.companyId])
    }else {

Hi @oflores2313,

Since you require user metadata to determine the redirect, you may want to add a custom claim to the ID Token instead of making a call to the Management API.

To do this, you can use a post-login action:

exports.onExecutePostLogin = async (event, api) => {
  const namespace = ''; // <-- custom claims require a URI namespace
  api.idToken.setCustomClaim(`${namespace}companyId`, event.user.app_metadata.companyId);

In your app, you can find the companyID without making an API request:

      (profile) => (this.companyId = profile[''])
    // ...

or in a template:

<p>{{ user[''] }}</p>

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