Description
Operating System
MacOS Sequoia Version 15.1.1
Environment (if applicable)
All browsers
Firebase SDK Version
11.6.1
Firebase SDK Product(s)
Auth
Project Tooling
React app with Next.js
Detailed Problem Description
Saw that there was a new Persistence.Cookie strategy for Auth in beta and decided to give it a try, since it should fix some Auth persistence issues we have in Safari. I'm mostly following the implementation from this PR.
It works great, except if a user logs in and doesn't close their browser for an hour, and the ID token expires, Firebase fails to refresh it. This logs the user out. Other persistence strategies don't seem to have this issue. I'm seeing that the error code is user-token-expired
.
This seems to be because:
- When
PersistenceUserManager.getCurrentUser
is called, the user is created using the stored cookie value. This user hasrefreshToken = null
since the cookie value is just a string with the ID token and does not have the refresh token. - When the ID token is about to expire or expired and
getIdToken
refreshed, this line fails since the refresh token isnull
.
Steps and code to reproduce issue
- Set auth persistence to
browserCookiePersistence
:
auth.setPersistence(browserCookiePersistence);
- Set up Next.JS middleware to handle browser cookie persistence (example)
- Without closing the browser tab/window, wait an hour so that the ID token expires (or lower the refresh interval so that the force refresh happens more quickly)
Expected result:
User remains logged in, and ID token is refreshed. Firebase makes a request to /__cookies__
endpoint to refresh the ID token.
Actual behavior
The ID token expires and is not refreshed. The error code received is user-token-expired
. A DELETE
request is sent to /__cookies__
endpoint to log the user out.