signUpWithEmailAndPassword method
Future<AuthUser<User>>
signUpWithEmailAndPassword(
{ - required String email,
- required String password,
})
override
Implementation
@override
Future<AuthUser<User>> signUpWithEmailAndPassword(
{required String email, required String password}) async {
final MonitoringService monitoringService = core.get<MonitoringService>();
var trace =
await monitoringService.createTrace(name: 'signUpWithEmailAndPassword');
trace.start();
try {
if (!isReady) {
throw LittlefishFirebaseAuthException('AUTH_INIT_000',
'$providerName: Firebase is not initialized, $providerName cannot sign up with email and password');
}
if (email.isEmpty || password.isEmpty) {
throw LittlefishFirebaseAuthException('AUTH_007',
'$providerName: Email or password is empty, $providerName cannot sign up with email and password');
}
logger.debug(
this,
"$providerName: Signing up with email:$email and password",
);
var r = await kInstance?.createUserWithEmailAndPassword(
email: email,
password: password,
);
if (r == null) {
throw LittlefishFirebaseAuthException('AUTH_011',
'$providerName: Sign up with email and password failed, $providerName cannot sign up with email and password');
}
if (r.user == null) {
throw LittlefishFirebaseAuthException('AUTH_012',
'$providerName: Sign up with email and password failed, $providerName cannot locate user information post-logon');
}
kUserCredential = r.credential;
logger.info(
this,
"$providerName: Signed up with email:$email and password",
);
return FirebaseAuthUser(
kUser: r.user!,
additionalUserInfo: _convertAdditionalUserInfo(r.additionalUserInfo),
baseUserId: r.user?.uid ?? '',
baseUserFirstName: r.user?.displayName ?? '',
baseUserLastName: r.user?.displayName ?? '',
baseUserEmail: r.user?.email ?? '',
baseUserRegisteredDate: r.user?.metadata.creationTime ?? DateTime.now(),
baseUserMobileNumber: r.user?.phoneNumber ?? '',
baseUserProfileImageUri: r.user?.photoURL ?? '',
baseUserGender: UserGender.notSpecified,
baseUserDisplayName: r.user?.displayName ?? '',
baseUserEmailVerified: r.user?.emailVerified ?? false,
);
} on FirebaseAuthException catch (e) {
throw _handleFirebaseAuthException(e);
} catch (e) {
if (e is LittlefishException) {
rethrow;
}
throw LittlefishFirebaseAuthException(
'AUTH_014',
'An unexpected error occurred during sign up.',
cause: e,
);
} finally {
trace.stop();
}
}