54 lines
1.1 KiB
TypeScript
54 lines
1.1 KiB
TypeScript
import { AuthApiClient } from '../../api/auth/AuthApiClient';
|
|
import type { LoginParamsDto, SignupParamsDto, SessionDataDto } from '../../dtos';
|
|
|
|
/**
|
|
* Auth Service
|
|
*
|
|
* Orchestrates authentication operations by coordinating API calls.
|
|
* All dependencies are injected via constructor.
|
|
*/
|
|
export class AuthService {
|
|
constructor(
|
|
private readonly apiClient: AuthApiClient
|
|
) {}
|
|
|
|
/**
|
|
* Sign up a new user
|
|
*/
|
|
async signup(params: SignupParamsDto): Promise<SessionDataDto> {
|
|
try {
|
|
return await this.apiClient.signup(params);
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Log in an existing user
|
|
*/
|
|
async login(params: LoginParamsDto): Promise<SessionDataDto> {
|
|
try {
|
|
return await this.apiClient.login(params);
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Log out the current user
|
|
*/
|
|
async logout(): Promise<void> {
|
|
try {
|
|
await this.apiClient.logout();
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get iRacing authentication URL
|
|
*/
|
|
getIracingAuthUrl(returnTo?: string): string {
|
|
return this.apiClient.getIracingAuthUrl(returnTo);
|
|
}
|
|
} |