volna
volna

Reputation: 2610

Firebase Auth: Manually detect if the current user has recently authenticated

By default, if the user signed in X time ago, Firebase will require him/her to reauthenticate via reauthenticateWithCredential in order to complete the action.

Is there a way to query the Firebase API if the user already qualifies for reauthentication before proceeding with next action?

Upvotes: 3

Views: 394

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600120

For certain sensitive operations the Firebase Authentication API require that the user has recently (re)authenticated with their credentials.

There is currently no way to detect whether a specific call will require such re-authentication, nor documentation on how long the interval is before Firebase requires re-authentication.

The proper way to implement this, is to perform the operation, and catch errors. If the error.code is auth/requires-recent-login ask the user to re-authenticate, call reauthenticateWithCredential with the fresh credentials, and then retry the operation.

Upvotes: 3

Related Questions