create method
Future<String?>
create({
- required CreateAuthProvider provider,
- required VoidCallback onUserStateChanged,
override
Register users by passing a class inheriting from CreateAuthProvider in provider.
The difference with register is that you can create another user even if you are already logged in.
Execute onUserStateChanged when a user's authentication state is changed.
Returns the user's ID as the return value.
CreateAuthProviderを継承したクラスをproviderで渡すことにより、ユーザーの登録を行います。
registerとの違いはすでにログインしている場合でも別のユーザーを作成することができることです。
ユーザーの認証状態が変更されたときにonUserStateChangedを実行します。
戻り値にユーザーのIDを返します。
Implementation
@override
Future<String?> create({
required CreateAuthProvider provider,
required VoidCallback onUserStateChanged,
}) async {
if (provider is EmailAndPasswordCreateAuthProvider) {
await _prepareProcessInternal();
_secondaryApp ??= await Firebase.initializeApp(
options: options,
name: _kSecondaryAppName,
);
_secondaryAuth ??= FirebaseAuth.instanceFor(app: _secondaryApp!);
await _secondaryAuth!.setLanguageCode(
provider.locale?.languageCode ?? defaultLocale.languageCode,
);
final credentials = await _secondaryAuth!.createUserWithEmailAndPassword(
email: provider.email,
password: provider.password,
);
onUserStateChanged.call();
return credentials.user?.uid;
}
return null;
}