signIn method
Future<SignInResponse>
signIn(
- String provider, {
- EmailSignInOptions? emailOptions,
- CredentialsSignInOptions? credentialsOptions,
- OAuthSignInOptions? oauthOptions,
Sign in with email, credentials or OAuth provider
- email: sign in with email (If the token is missing in emailOptions, a verification code will be sent to the email and a token will be returned. Otherwise, the server-side sign-in process will be invoked. Therefore, the email sign-in flow requires calling this method twice.)
- credentials: sign in with credentials (you are responsible for providing the credentials to the signIn method)
- OAuth provider: sign in with OAuth provider (you are responsible for implementing the OAuth provider)
Implementation
Future<SignInResponse> signIn(
String provider, {
EmailSignInOptions? emailOptions,
CredentialsSignInOptions? credentialsOptions,
OAuthSignInOptions? oauthOptions,
}) async {
try {
SignInResponse response;
if (provider == 'email') {
assert(
emailOptions != null,
'emailOptions is required for email provider',
);
response = await _signInWithEmail(emailOptions!);
} else if (provider == 'credentials') {
assert(
credentialsOptions != null,
'credentialsOptions is required for credentials provider',
);
response = await _signInWithCredentials(credentialsOptions!);
} else {
assert(
oauthOptions != null,
'oauthOptions is required for OAuth provider',
);
response = await _signInWithOAuth(provider, oauthOptions!);
}
return response;
} catch (e) {
logger?.error('signIn error', e);
return SignInResponse(
error: SignInError(
code: SignInErrorCode.serverError,
exception: e is Exception ? e : SignInException.fromObject(e),
),
status: 500,
ok: false,
);
}
}