email method

Future<AuthResponse<Session>> email({
  1. required String email,
  2. required String password,
  3. SignInCallbacks? callbacks,
})

Signs in with email and password authentication.

email The user's email address. password The user's password. callbacks Optional lifecycle callbacks.

Returns an AuthResponse containing the Session on success.

Example:

final response = await authClient.signIn.email(
  email: 'user@example.com',
  password: 'password123',
);

if (response.isSuccess) {
  print('Welcome, ${response.data!.user.name}');
}

Implementation

Future<AuthResponse<Session>> email({
  required String email,
  required String password,
  SignInCallbacks? callbacks,
}) async {
  callbacks?.onRequest?.call();

  try {
    final response = await _dio.post(
      ApiEndpoints.signInEmail,
      data: {
        'email': email,
        'password': password,
      },
    );

    final session = Session.fromJson(response.data['session'] ?? response.data);
    await _tokenManager.setAccessToken(session.token);
    callbacks?.onSuccess?.call(session);

    return AuthResponse.success(session);
  } on DioException catch (e) {
    final error = AuthError.fromDio(e);
    callbacks?.onError?.call(error);
    return AuthResponse.error(error);
  }
}