# Angular App gets undefined value for token

**URL:** <https://devforum.okta.com/t/angular-app-gets-undefined-value-for-token/14316>\
**Category:** OAuth/OIDC\
**Created:** [May 19, 2021, 11:34pm UTC](https://devforum.okta.com/t/angular-app-gets-undefined-value-for-token/14316 "2021-05-19T23:34:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eber](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@Eber](https://devforum.okta.com/u/Eber)\
**Post date:** [May 19, 2021, 11:34pm UTC](https://devforum.okta.com/t/angular-app-gets-undefined-value-for-token/14316/1 "2021-05-19T23:34:19Z")

</div>

We’re having some trouble with our angular spa app. On our localhost and qa sites everything works fine. The problem happens on our production environment. After the login by the user (two step authentication), the browser redirects to login/callback. The problem here is that there are no calls to the token api, so the token is null (using getAccessToken()). There is no token on local storage or cookies. Also the isAuthenticated method returns false. Why is this happening?, how can I solve this?. Maybe after the redirect there is no variable indicating that this is a redirect so the token api call never happens?.

---

<div class="post-metadata">

**Author:** ![Lijia](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/lijia/32/2295_2.png) [@Lijia](https://devforum.okta.com/u/Lijia)\
**Post date:** [May 21, 2021, 6:35am UTC](https://devforum.okta.com/t/angular-app-gets-undefined-value-for-token/14316/2 "2021-05-21T06:35:34Z")

</div>

@Eber Hi, for “qa sites” you mentioned, do you mean it is working in dev or preview account? And the issue only happens in production org?  
Can you please check if you have the access to Security → API → Trusted Origin tab. Did you add your URI there?

---

<div class="post-metadata">

**Author:** ![Eber](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@Eber](https://devforum.okta.com/u/Eber)\
**Post date:** [May 21, 2021, 4:04pm UTC](https://devforum.okta.com/t/angular-app-gets-undefined-value-for-token/14316/3 "2021-05-21T16:04:20Z")

</div>

Hi, thanks for the reply. Yes, in qa and dev we work using a preview account. In this preview account we hace access to trusted origin tab and we have added our site there. The user is yet to confirm us if they have set the production site on trusted origins. Also, they told us that when they create a spa app registration, the don’t use pkce. Since I’m using a preview account that option is blocked (always marked). Is it possible to create a SPA app without pkce?, and If that is the case, can I handle that on angular?

---

<div class="post-metadata">

**Author:** ![Lijia](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/lijia/32/2295_2.png) [@Lijia](https://devforum.okta.com/u/Lijia)\
**Post date:** [May 24, 2021, 6:04pm UTC](https://devforum.okta.com/t/angular-app-gets-undefined-value-for-token/14316/4 "2021-05-24T18:04:15Z")

</div>

@Eber If preview orgs work, I suggest you can make sure your production org configuration settings exactly same with your preview. Please check if your users have access to trusted origins. If not, they may need to purchase API AM feature since this FF is not free in production org.  
The below is the steps to create SPA. The PKCE flow is enabled by default.  
[https://developer.okta.com/docs/guides/sign-into-spa/vue/create-okta-application/](https://developer.okta.com/docs/guides/sign-into-spa/vue/create-okta-application/)  
Are you trying to build native app? or other apps?

---

<div class="post-metadata">

**Author:** ![Eber](https://avatars.discourse-cdn.com/v4/letter/e/74df32/32.png) [@Eber](https://devforum.okta.com/u/Eber)\
**Post date:** [May 25, 2021, 9:17pm UTC](https://devforum.okta.com/t/angular-app-gets-undefined-value-for-token/14316/5 "2021-05-25T21:17:53Z")

</div>

@Lijia thanks for your help. We’ve confirmation about the configuration and, indeed, PKCE is enabled. The only thing missing is to confirm that the site is in the trusted origins list. If it’s not, could that be causing the null token error?

---

<div class="post-metadata">

**Author:** ![Lijia](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/lijia/32/2295_2.png) [@Lijia](https://devforum.okta.com/u/Lijia)\
**Post date:** [June 1, 2021, 11:36pm UTC](https://devforum.okta.com/t/angular-app-gets-undefined-value-for-token/14316/6 "2021-06-01T23:36:16Z")

</div>

@Eber You need to add the redirect URI to trusted origin as well. Please try to add that configuration first.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [April 25, 2022, 6:10pm UTC](https://devforum.okta.com/t/angular-app-gets-undefined-value-for-token/14316/7 "2022-04-25T18:10:53Z")

</div>

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