signIn method

Future<GotrueSessionResponse> signIn({
  1. String? email,
  2. String? phone,
  3. String? password,
  4. Provider? provider,
  5. OpenIDConnectCredentials? oidc,
  6. AuthOptions? options,
})

Log in an existing user, or login via a third-party provider.

Implementation

Future<GotrueSessionResponse> signIn({
  String? email,
  String? phone,
  String? password,
  Provider? provider,
  OpenIDConnectCredentials? oidc,
  AuthOptions? options,
}) async {
  _removeSession();

  if (email != null && password == null) {
    final response = await api.sendMagicLinkEmail(email, options: options);
    return GotrueSessionResponse(error: response.error);
  }
  if (email != null && password != null) {
    return _handleEmailSignIn(email, password, options: options);
  }
  if (phone != null && password == null) {
    final response = await api.sendMobileOTP(phone);
    return GotrueSessionResponse(error: response.error);
  }
  if (phone != null && password != null) {
    return _handlePhoneSignIn(phone, password);
  }
  if (provider != null) {
    return _handleProviderSignIn(provider, options);
  }
  if (oidc != null) {
    return _handleOpenIDConnectSignIn(oidc);
  }
  final error = GotrueError(
    "You must provide either an email, phone number, a third-party provider or OpenID Connect.",
  );
  return GotrueSessionResponse(error: error);
}