# How to stay logged in forever(ish)

**URL:** <https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926>\
**Category:** Get Help\
**Tags:** login\
**Created:** [May 17, 2021, 2:58pm UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926 "2021-05-17T14:58:53Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![projuljustin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/projuljustin/32/13081_2.png) [@projuljustin](https://community.auth0.com/u/projuljustin)\
**Post date:** [May 17, 2021, 2:58pm UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/1 "2021-05-17T14:58:53Z")

</div>

Hey there, my company is making the switch to Auth0 and our main goal is ensuring that our users don’t have to log in if they are active during a 14 day period. If they continue to make calls and refresh their tokens, they should never be logged out. If they try to refresh a token outside of the 14 days they get logged out.

I believe this could be achieved by turning off “Refresh Token Rotation” and “Absolute Expiration”, but leaving on “Inactivity Expiration” and setting to 1209600 seconds.

My concern is that due to the tenant session “Require log in after” setting, my users will be logged out after 30 days regardless of the refresh token settings and forced to log back in.

Can anyone confirm this for me?

Much appreciated!

---

<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:** [May 18, 2021, 12:00am UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/3 "2021-05-18T00:00:43Z")

</div>

Hi @projuljustin,

Welcome to the Community!

It depends on what type of application you are running (single page app, native app, traditional web app) and what plan you are on.

This blog does a good job of laying out the app vs. plan types:

> **[Balance User Experience and Security to Retain Customers](https://auth0.com/blog/balance-user-experience-and-security-to-retain-customers/)**
>
> Balance User Experience and Security to Retain Customers. Long-lived sessions improve UX while reducing password reset costs.

---

<div class="post-metadata">

**Author:** ![projuljustin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/projuljustin/32/13081_2.png) [@projuljustin](https://community.auth0.com/u/projuljustin)\
**Post date:** [May 18, 2021, 12:17am UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/4 "2021-05-18T00:17:25Z")

</div>

We’re running an SPA and for our dev environment are on a free plan.

Is there a certain plan we would need to keep users logged in indefinitely?

---

<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:** [May 18, 2021, 12:46am UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/5 "2021-05-18T00:46:00Z")

</div>

Enterprise customers have access to a _long lived sessions_ feature, 100 Days Inactivity/365 Days Total Timeout.

---

<div class="post-metadata">

**Author:** ![projuljustin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/projuljustin/32/13081_2.png) [@projuljustin](https://community.auth0.com/u/projuljustin)\
**Post date:** [May 18, 2021, 1:23am UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/6 "2021-05-18T01:23:24Z")

</div>

To clarify the sessions, once your refresh token is expired you use the local or server side session to get a new refresh token. If you attempt to do this refresh and the session is expired, the user is logged out correct?

So for a standard plan, any user will be logged out after 30 days + refresh token expiration, correct?

In theory, if you set the refresh token to something really long like 90 days, they would be logged in for 90 days, the refresh would expire, and the session is already expired, they would be signed out. Correct?

---

<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:** [May 20, 2021, 5:28pm UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/7 "2021-05-20T17:28:31Z")

</div>

> [@projuljustin](#):
>
> once your refresh token is expired you use the local or server side session to get a new refresh token.

The existing refresh token is used to request a new refresh token (and access token).

> [@projuljustin](#):
>
> If you attempt to do this refresh and the session is expired, the user is logged out correct?

If the _absolute lifetime for the family of refresh tokens is expired_ the user is forced to authenticate.

From the docs:

> - **Absolute Lifetime** : Set a refresh token or refresh token family lifetime after which the user must re-authenticate before being issued a new access token.

> [@projuljustin](#):
>
> So for a standard plan, any user will be logged out after 30 days + refresh token expiration, correct?

I will have to check on this.

> [@projuljustin](#):
>
> In theory, if you set the refresh token to something really long like 90 days, they would be logged in for 90 days, the refresh would expire, and the session is already expired, they would be signed out. Correct?

I think this goes back to the previous question, whether or not the Login Session settings supersede the token lifetimes and force logout. I’ll ask the team and get back to you.

---

<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:** [May 20, 2021, 9:28pm UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/8 "2021-05-20T21:28:33Z")

</div>

Here is what I gathered from speaking to the team:

The session settings and the refresh tokens are separate. The session settings ( `Require log in after` , `Inactivity timeout`) are specifically for the session cookie that is set after authentication. If you are using refresh token rotation, those limits will define when a user will need to re-authenticate.

---

<div class="post-metadata">

**Author:** ![projuljustin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/projuljustin/32/13081_2.png) [@projuljustin](https://community.auth0.com/u/projuljustin)\
**Post date:** [May 24, 2021, 1:08pm UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/9 "2021-05-24T13:08:14Z")

</div>

If I’m using refresh token rotation, and my session is expired, but my refresh token is not expired, will I still be authenticated and be able to get a new refresh and access token?

---

<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:** [May 24, 2021, 4:13pm UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/10 "2021-05-24T16:13:58Z")

</div>

That is correct, yes.

---

<div class="post-metadata">

**Author:** ![projuljustin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/projuljustin/32/13081_2.png) [@projuljustin](https://community.auth0.com/u/projuljustin)\
**Post date:** [June 7, 2021, 7:28pm UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/11 "2021-06-07T19:28:24Z")

</div>

@dan.woda - I just had a scenario where a test user was logged out after ~3 days of inactivity after a getAccessTokenSilently() call failed with “Login required”. I see this function is supposed to use refresh tokens, but I don’t see a refresh token being used in the token request.

We’re using the React SDK, and on 401 or 403 from an API call we run this function.

const getAccessToken = async () =\> {  
try {  
const token = await getAccessTokenSilently();  
setAccessToken(token);  
document.token = token;  
console.log(“SILENTLY AQUIRED USER-TOKEN”, token);  
return token;  
} catch (e) {  
console.error(“SILENTLY AQUIRED USER-TOKEN”, e);  
}  
}

Tenant settings  
Session inactivity timeout: 4320  
Session require log in after: 10080

SPA settings  
Refresh token rotation: Enabled  
Refresh token rotation reuse: 60  
Refresh token absolute expiration: Enabled  
Refresh token absolute lifetime: 31536000  
Refresh token inactivity expiration: Enabled  
Refresh token inactivity lifetime: 2592000

---

<div class="post-metadata">

**Author:** ![projuljustin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/projuljustin/32/13081_2.png) [@projuljustin](https://community.auth0.com/u/projuljustin)\
**Post date:** [June 7, 2021, 9:39pm UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/12 "2021-06-07T21:39:43Z")

</div>

In the response I see we are only passed an access\_token and an id\_token. Since I have refresh token rotation turned on, shouldn’t a refresh token be returned too?

> **[Authorization Code Flow with Proof Key for Code Exchange (PKCE)](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-proof-key-for-code-exchange-pkce)**
>
> Learn how the Authorization Code flow with Proof Key for Code Exchange (PKCE) works and why you should use it for native and mobile apps.

![image](https://global.discourse-cdn.com/auth0/original/3X/e/b/ebd5d0a5353471210ab22b4a9c45fe93d7b06f3d.png)

---

<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:** [June 7, 2021, 9:48pm UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/13 "2021-06-07T21:48:24Z")

</div>

Have you configured your app to use refresh tokens? You need to tell the SDK to request one. From our docs:

> The `getAccessTokenSilently()` method can renew the access and ID token for you using [refresh tokens](https://auth0.com/docs/tokens/concepts/refresh-tokens). To [get a refresh token](https://auth0.com/docs/tokens/guides/get-refresh-tokens) when a user logs in, pass `useRefreshTokens={true}` as a prop to `Auth0Provider` .

---

<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:** [July 13, 2021, 4:32pm UTC](https://community.auth0.com/t/how-to-stay-logged-in-forever-ish/62926/14 "2021-07-13T16:32:43Z")

</div>

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