email method

Future<AuthResponse<User>> email({
  1. required String email,
  2. required String password,
  3. String? name,
  4. SignUpCallbacks? callbacks,
})

Signs up with email and password.

email The user's email address (required). password The user's password (required). name The user's display name (optional). callbacks Optional lifecycle callbacks.

Returns an AuthResponse containing the new User on success.

Example:

final response = await authClient.signUp.email(
  email: 'user@example.com',
  password: 'password123',
  name: 'John Doe',
);

if (response.isSuccess) {
  print('Account created: ${response.data!.email}');
}

Implementation

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

  try {
    final response = await _dio.post(
      ApiEndpoints.signUpEmail,
      data: {
        'email': email,
        'password': password,
        if (name != null) 'name': name,
      },
    );

    final user = User.fromJson(response.data['user'] ?? response.data);
    callbacks?.onSuccess?.call(user);

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