42 lines
1.1 KiB
Dart
42 lines
1.1 KiB
Dart
import '../../../../data/network/api_client.dart';
|
|
import '../models/session_response.dart';
|
|
|
|
class AuthApi {
|
|
AuthApi({required ApiClient apiClient}) : _apiClient = apiClient;
|
|
|
|
final ApiClient _apiClient;
|
|
|
|
Future<void> sendOtp({required String email}) async {
|
|
await _apiClient.postNoContent(
|
|
'/api/v1/auth/otp/send',
|
|
data: {'email': email},
|
|
);
|
|
}
|
|
|
|
Future<SessionResponse> createEmailSession({
|
|
required String email,
|
|
required String token,
|
|
}) async {
|
|
final json = await _apiClient.postJson(
|
|
'/api/v1/auth/email-session',
|
|
data: {'email': email, 'token': token},
|
|
);
|
|
return SessionResponse.fromJson(json);
|
|
}
|
|
|
|
Future<void> deleteSession({required String refreshToken}) async {
|
|
await _apiClient.deleteNoContent(
|
|
'/api/v1/auth/sessions',
|
|
data: {'refresh_token': refreshToken},
|
|
);
|
|
}
|
|
|
|
Future<SessionResponse> refreshSession({required String refreshToken}) async {
|
|
final json = await _apiClient.postJson(
|
|
'/api/v1/auth/sessions/refresh',
|
|
data: {'refresh_token': refreshToken},
|
|
);
|
|
return SessionResponse.fromJson(json);
|
|
}
|
|
}
|