confirmChange method

Future<void> confirmChange({
  1. required ConfirmChangeAuthProvider provider,
})

If you change with ChangePhoneNumberAuthProvider, for example, you need to check the authentication code you received from an email or SMS. In that case, use this method to finalize the change.

Confirm sign-in by passing a class inheriting from ConfirmChangeAuthProvider with provider.

ChangePhoneNumberAuthProviderなどでchangeした場合、メールやSMSから受け取った認証コードをチェックする必要があります。 その場合、このメソッドを利用して変更を確定させてください。

ConfirmChangeAuthProviderを継承したクラスをproviderで渡すことにより、サインインを確定させます。

Implementation

Future<void> confirmChange({
  required ConfirmChangeAuthProvider provider,
}) async {
  await _initialize();
  final account = active;
  if (account == null) {
    throw Exception(
      "You are not signed in. Please sign in with [signIn] first.",
    );
  }
  final userId = account.get(userIdKey, "");
  if (provider is ConfirmChangePhoneNumberAuthProvider) {
    final phoneNumber = account.get(tmpUserPhoneNumberKey, "");
    if (phoneNumber.isEmpty) {
      throw Exception(
        "Phone number is not registered. Please register it with [signIn] beforehand.",
      );
    }
    if (provider.code != account.get(smsCodeKey, "")) {
      throw Exception(
        "The code is invalid. Please check the code.",
      );
    }
    _data._setAccount(userId, {
      ...account,
      userPhoneNumberKey: phoneNumber,
    });
  }
  await onSaved?.call(this);
}