apiRestore static method

Future<FirebaseAccount> apiRestore(
  1. RestApi api,
  2. String refreshToken, {
  3. bool autoRefresh = true,
  4. String? locale,
})

Restores an account by using a refresh token to log the user in again.

If a user has logged in once normally, you can store the refreshToken and the later use this method to recreate the account instance without the user logging in again. Internally, this method calls refresh() to obtain user credentails and the returns a newly created account from the result.

The account is created by using the api for accessing the Firebase REST endpoints. If autoRefresh and locale are used to initialize these properties.

If the refreshing fails, an AuthException will be thrown.

Implementation

static Future<FirebaseAccount> apiRestore(
  RestApi api,
  String refreshToken, {
  bool autoRefresh = true,
  String? locale,
}) async {
  final response = await api.token(refresh_token: refreshToken);
  return FirebaseAccount._(
    api,
    response.user_id,
    response.id_token,
    response.refresh_token,
    _expiresInToAt(_durFromString(response.expires_in)),
    locale,
  )..autoRefresh = autoRefresh;
}