api client refactor
This commit is contained in:
40
apps/website/lib/api/auth/AuthApiClient.ts
Normal file
40
apps/website/lib/api/auth/AuthApiClient.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user