confirmSignIn method
If you signIn with EmailLinkSignInAuthProvider or SmsSignInAuthProvider, you need to check the authentication code received from email or SMS. In that case, use this method to finalize the sign-in.
Confirm sign-in is confirmed by passing a class inheriting from ConfirmSignInAuthProvider in provider
.
EmailLinkSignInAuthProviderやSmsSignInAuthProviderなどでsignInした場合、メールやSMSから受け取った認証コードをチェックする必要があります。 その場合、このメソッドを利用してサインインを確定させてください。
ConfirmSignInAuthProviderを継承したクラスをprovider
で渡すことにより、サインインを確定させます。
Implementation
Future<void> confirmSignIn({
required ConfirmSignInAuthProvider provider,
}) async {
await _initialize();
if (provider is EmailLinkConfirmSignInAuthProvider) {
final temporary = _data._getTemporary();
final emailLink = temporary.get(emailLinkUrlKey, "");
final email = temporary.get(tmpUserEmailKey, "");
if (temporary.isEmpty || emailLink != provider.url || email.isEmpty) {
throw Exception(
"Your Email is not registered. Please register it with [signIn] beforehand.",
);
}
final userId = temporary.get(userIdKey, "");
final allowMultiProvider = _data._getTemporaryAllowMultiProvider();
_data._clearTemporary();
final providers = [
...temporary.getAsList(activeProvidersKey),
provider.providerId
].distinct();
if (!allowMultiProvider && providers.length > 1) {
throw Exception(
"Signing in with multiple providers is not allowed.",
);
}
_data._setAccount(userId, {
...temporary,
AuthDatabase.userEmailKey: email,
activeProvidersKey: [
...temporary.getAsList(activeProvidersKey),
provider.providerId
].distinct()
});
_data._setCurrent(userId);
_activeId = userId;
} else if (provider is SmsConfirmSignInAuthProvider) {
final temporary = _data._getTemporary();
final phoenNumber = temporary.get(tmpUserPhoneNumberKey, "");
if (temporary.isEmpty || phoenNumber.isEmpty) {
throw Exception(
"Phone number is not registered. Please register it with [signIn] beforehand.",
);
}
if (provider.code != temporary.get(smsCodeKey, "")) {
throw Exception(
"The code is invalid. Please check the code.",
);
}
final userId = temporary.get(userIdKey, "");
final allowMultiProvider = _data._getTemporaryAllowMultiProvider();
_data._clearTemporary();
final providers = [
...temporary.getAsList(activeProvidersKey),
provider.providerId
].distinct();
if (!allowMultiProvider && providers.length > 1) {
throw Exception(
"Signing in with multiple providers is not allowed.",
);
}
_data._setAccount(userId, {
...temporary,
AuthDatabase.userPhoneNumberKey: phoenNumber,
activeProvidersKey: [
...temporary.getAsList(activeProvidersKey),
provider.providerId
].distinct()
});
_data._setCurrent(userId);
_activeId = userId;
}
await onSaved?.call(this);
}