signInEmailPassword method
Authenticates a user using an email
and password
.
If the user has multi-factor authentication enabled, the returned
AuthResponse
will only have its AuthResponse.mfa
field set, which can
then be used to complete the sign in via completeMfaSignIn alongside the
user's one-time-password.
Throws an NhostException
if sign in fails.
Implementation
@override
Future<AuthResponse> signInEmailPassword({
required String email,
required String password,
}) async {
log.finer('Attempting sign in (email-password)');
AuthResponse? res;
try {
res = await _apiClient.post(
'/signin/email-password',
jsonBody: {
'email': email,
'password': password,
},
responseDeserializer: AuthResponse.fromJson,
);
} catch (e, st) {
log.finer('Sign in failed', e, st);
await clearSession();
rethrow;
}
// If multi-factor is enabled, a second step is required before we've fully
// logged in.
if (res!.mfa != null) {
log.finer('Sign in requires MFA');
return res;
}
log.finer('Sign in successful');
await setSession(res.session!);
return res;
}