40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { BaseApiClient } from '../base/BaseApiClient';
|
|
import type {
|
|
LoginParamsDto,
|
|
SignupParamsDto,
|
|
SessionDataDto,
|
|
} from '../../dtos';
|
|
|
|
/**
|
|
* Auth API Client
|
|
*
|
|
* Handles all authentication-related API operations.
|
|
*/
|
|
export class AuthApiClient extends BaseApiClient {
|
|
/** Sign up with email */
|
|
signup(params: SignupParamsDto): Promise<SessionDataDto> {
|
|
return this.post<SessionDataDto>('/auth/signup', params);
|
|
}
|
|
|
|
/** Login with email */
|
|
login(params: LoginParamsDto): Promise<SessionDataDto> {
|
|
return this.post<SessionDataDto>('/auth/login', params);
|
|
}
|
|
|
|
/** Get current session */
|
|
getSession(): Promise<SessionDataDto | null> {
|
|
return this.get<SessionDataDto | null>('/auth/session');
|
|
}
|
|
|
|
/** Logout */
|
|
logout(): Promise<void> {
|
|
return this.post<void>('/auth/logout', {});
|
|
}
|
|
|
|
/** Start iRacing auth redirect */
|
|
getIracingAuthUrl(returnTo?: string): string {
|
|
const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://localhost:3001';
|
|
const params = returnTo ? `?returnTo=${encodeURIComponent(returnTo)}` : '';
|
|
return `${baseUrl}/auth/iracing/start${params}`;
|
|
}
|
|
} |