5e169251fe
- Remove ApiClientWrapper and MockApiClientWrapper - Simplify IApiClient interface - Update dependency injection configuration - Optimize calendar service and AG-UI chat models
69 lines
1.9 KiB
Dart
69 lines
1.9 KiB
Dart
import 'package:social_app/core/api/i_api_client.dart';
|
|
import 'models/signup_request.dart';
|
|
import 'models/login_request.dart';
|
|
import 'models/auth_response.dart';
|
|
|
|
class AuthApi {
|
|
final IApiClient _client;
|
|
static const _prefix = '/api/v1/auth';
|
|
|
|
AuthApi(this._client);
|
|
|
|
Future<VerificationCreateResponse> createVerification(
|
|
SignupStartRequest request,
|
|
) async {
|
|
final response = await _client.post(
|
|
'$_prefix/verifications',
|
|
data: request.toJson(),
|
|
);
|
|
return VerificationCreateResponse.fromJson(response.data);
|
|
}
|
|
|
|
Future<AuthResponse> verifyVerification(SignupVerifyRequest request) async {
|
|
final response = await _client.post(
|
|
'$_prefix/verifications/verify',
|
|
data: request.toJson(),
|
|
);
|
|
return AuthResponse.fromJson(response.data);
|
|
}
|
|
|
|
Future<void> resendVerification(SignupResendRequest request) async {
|
|
await _client.post('$_prefix/verifications/resend', data: request.toJson());
|
|
}
|
|
|
|
Future<AuthResponse> createSession(LoginRequest request) async {
|
|
final response = await _client.post(
|
|
'$_prefix/sessions',
|
|
data: request.toJson(),
|
|
);
|
|
return AuthResponse.fromJson(response.data);
|
|
}
|
|
|
|
Future<AuthResponse> refreshSession(RefreshRequest request) async {
|
|
final response = await _client.post(
|
|
'$_prefix/sessions/refresh',
|
|
data: request.toJson(),
|
|
);
|
|
return AuthResponse.fromJson(response.data);
|
|
}
|
|
|
|
Future<void> deleteSession(LogoutRequest request) async {
|
|
await _client.delete('$_prefix/sessions', data: request.toJson());
|
|
}
|
|
|
|
Future<void> requestPasswordReset(String email) async {
|
|
await _client.post('$_prefix/password-reset', data: {'email': email});
|
|
}
|
|
|
|
Future<void> confirmPasswordReset({
|
|
required String email,
|
|
required String token,
|
|
required String newPassword,
|
|
}) async {
|
|
await _client.post(
|
|
'$_prefix/password-reset/confirm',
|
|
data: {'email': email, 'token': token, 'new_password': newPassword},
|
|
);
|
|
}
|
|
}
|