# Angular SDK, auth state lost upon page refresh with refreshtokens

**URL:** <https://community.auth0.com/t/angular-sdk-auth-state-lost-upon-page-refresh-with-refreshtokens/113825>\
**Category:** Get Help\
**Tags:** configuration, application\
**Created:** [August 17, 2023, 7:01am UTC](https://community.auth0.com/t/angular-sdk-auth-state-lost-upon-page-refresh-with-refreshtokens/113825 "2023-08-17T07:01:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris\_b](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chris_b/32/72555_2.png) [@chris\_b](https://community.auth0.com/u/chris_b)\
**Post date:** [August 17, 2023, 7:01am UTC](https://community.auth0.com/t/angular-sdk-auth-state-lost-upon-page-refresh-with-refreshtokens/113825/1 "2023-08-17T07:01:42Z")

</div>

Hi all,

I am currently doing an implementation with auth0 where I want to have an angular frontend for an api.

I enabled the refresh token rotation in my spa application, set a reuse interval of 30 seconds and enabled offline access in the api application.

When I download the quickstart example which is already configured I can do page reloads without losing authentication. However, as soon as I add `useRefreshTokens: true` to the environment configuration I see the login screen again.

I confirmed with chrome developer tools that for the login a refreshtoken is returned. The whole response looks like this:

```auto
access_token: "eyJhbGc..."
expires_in: 86400
id_token: "eyJhb.."
refresh_token: "v1.Mf0.."
scope: "openid profile email offline_access"
token_type: "Bearer"

```

When I reload a page I don’t see any requests made to a token endpoint. Also, with `cacheLocation: 'localstorage'` page reloads work, but this is probably not ideal? I expected that I don’t have to use localStorage with refreshtokens.

app module:

```auto
@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    ProfileComponent,
    NavBarComponent,
    FooterComponent,
    HeroComponent,
    HomeContentComponent,
    LoadingComponent,
    ExternalApiComponent,
    ErrorComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    NgbModule,
    HighlightModule,
    FontAwesomeModule,
    AuthModule.forRoot({
      cacheLocation: 'localstorage',
      useRefreshTokens: true,
      ...env.auth,
      httpInterceptor: {
        ...env.httpInterceptor,
      },
    }),
  ],
  providers: [
    {
      provide: HTTP_INTERCEPTORS,
      useClass: AuthHttpInterceptor,
      multi: true,
    },
    {
      provide: Window,
      useValue: window,
    },
    {
      provide: HIGHLIGHT_OPTIONS,
      useValue: {
        coreLibraryLoader: () => import('highlight.js/lib/core'),
        languages: {
          json: () => import('highlight.js/lib/languages/json'),
        },
      },
    },
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

```

Is there any configuration I am missing in my tenant?

Hopeing for any tips in the right direction.

Best  
Chris

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 18, 2023, 2:58pm UTC](https://community.auth0.com/t/angular-sdk-auth-state-lost-upon-page-refresh-with-refreshtokens/113825/3 "2023-08-18T14:58:17Z")

</div>

Hi @chris_b,

You can use the `cacheLocation: 'localstorage'` setting. This setting is storing the refresh token in localstorage, which is different from storing an access token in localstorage.

There’s more info on the subject here: [Can I save Refresh Token into localStorage if `Refresh Token Rotation` is enabled? - #3 by dan.woda](https://community.auth0.com/t/can-i-save-refresh-token-into-localstorage-if-refresh-token-rotation-is-enabled/46761/3)

---

<div class="post-metadata">

**Author:** ![chris\_b](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/chris_b/32/72555_2.png) [@chris\_b](https://community.auth0.com/u/chris_b)\
**Post date:** [August 19, 2023, 9:25am UTC](https://community.auth0.com/t/angular-sdk-auth-state-lost-upon-page-refresh-with-refreshtokens/113825/4 "2023-08-19T09:25:55Z")

</div>

Hi @dan.woda,

thanks for the reply and the linked information!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 21, 2023, 1:01pm UTC](https://community.auth0.com/t/angular-sdk-auth-state-lost-upon-page-refresh-with-refreshtokens/113825/5 "2023-08-21T13:01:27Z")

</div>

No problem, please let us know if you have any questions.

---

<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:** [September 4, 2023, 1:02pm UTC](https://community.auth0.com/t/angular-sdk-auth-state-lost-upon-page-refresh-with-refreshtokens/113825/6 "2023-09-04T13:02:14Z")

</div>

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