Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

auth/user-token-expired thrown by getIdToken #407

Open
winqoo opened this issue Oct 18, 2021 · 0 comments
Open

auth/user-token-expired thrown by getIdToken #407

winqoo opened this issue Oct 18, 2021 · 0 comments

Comments

@winqoo
Copy link

winqoo commented Oct 18, 2021

I have a refresh method in my code that calls firebaseUser?.getIdToken();. The problem start to happen when user is in the app for approx 1h. the code throws auth/user-token-expired error and the user is force to logout.

Future<String?> _refreshToken() async {
    var firebaseUser = await firebaseAuth.currentUser;
    _tokenCreationDate = DateTime.now();
    try {
      _token = await firebaseUser?.getIdToken(true);
      return _token;
    } on PlatformException catch (e) {
      if (e.code == 'ERROR_USER_TOKEN_EXPIRED') {
        await errorTracking.captureException(
            exception: e,
            stackTrace:
                'firebase _refreshToken PlatformException ERROR_USER_TOKEN_EXPIRED');
        await signOut();
        throw TokenExpiredError(e);
      }
    } catch (e) {
      logger.e(e);
    }
    return null;
  }

it goes straight to the catch. From the documentation I know that:

Firebase ID tokens are short lived and last for an hour; the refresh token can be used to retrieve new ID tokens. Refresh tokens expire only when one of the following occurs: The user is deleted. The user is disabled. Which is not the case here. Is there any other reason why the method throws exception?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant