getSession method
Fetches the current session from the server.
Returns an AuthResponse containing the session data on success, or an AuthError on failure.
Example:
final response = await authClient.getSession();
if (response.isSuccess) {
print('Session expires: ${response.data!.expiresAt}');
}
Implementation
Future<AuthResponse<Session>> getSession() async {
try {
final response = await _dio.get(
ApiEndpoints.getSession,
options: Options(
headers: {'Content-Type': 'application/json'},
),
);
final session =
Session.fromJson(response.data['session'] ?? response.data);
_sessionNotifier.value = session;
return AuthResponse.success(session);
} on DioException catch (e) {
final error = AuthError.fromDio(e);
return AuthResponse.error(error);
}
}