# Angular SDK Subscribe crash

**URL:** <https://community.auth0.com/t/angular-sdk-subscribe-crash/63026>\
**Category:** Get Help\
**Tags:** sdk, angular, auth0\
**Created:** [May 18, 2021, 10:07pm UTC](https://community.auth0.com/t/angular-sdk-subscribe-crash/63026 "2021-05-18T22:07:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oflores2313](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oflores2313/32/28356_2.png) [@oflores2313](https://community.auth0.com/u/oflores2313)\
**Post date:** [May 18, 2021, 10:07pm UTC](https://community.auth0.com/t/angular-sdk-subscribe-crash/63026/1 "2021-05-18T22:07:17Z")

</div>

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) => {
     if(data){
       this.http.get(`https://${domain}/api/v2/users/${data.sub}`).subscribe(
         user => {
          this.profile = user
          if(this.profile.app_metadata){
            this.companyId = this.profile.app_metadata.companyId
          }
         }
         )
     }
  });

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

```

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 20, 2021, 8:16pm UTC](https://community.auth0.com/t/angular-sdk-subscribe-crash/63026/3 "2021-05-20T20:16:28Z")

</div>

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:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://test.com/'; // <-- 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:

```auto
this.auth.user$.subscribe(
      (profile) => (this.companyId = profile['https://test.com/companyId'])
    );
    // ...

```

or in a template:

```auto
<p>{{ user['https://test.com/companyId'] }}</p>

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 4, 2021, 8:16pm UTC](https://community.auth0.com/t/angular-sdk-subscribe-crash/63026/4 "2021-06-04T20:16:35Z")

</div>

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