40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { BaseApiClient } from '../base/BaseApiClient';
|
|
import { AuthSessionDTO } from '../../types/generated/AuthSessionDTO';
|
|
|
|
// TODO: Create DTOs for login/signup params in apps/website/lib/types/generated
|
|
type LoginParamsDto = { email: string; password: string };
|
|
type SignupParamsDto = { email: string; password: string; displayName: string };
|
|
|
|
/**
|
|
* Auth API Client
|
|
*
|
|
* Handles all authentication-related API operations.
|
|
*/
|
|
export class AuthApiClient extends BaseApiClient {
|
|
/** Sign up with email */
|
|
signup(params: SignupParamsDto): Promise<AuthSessionDTO> {
|
|
return this.post<AuthSessionDTO>('/auth/signup', params);
|
|
}
|
|
|
|
/** Login with email */
|
|
login(params: LoginParamsDto): Promise<AuthSessionDTO> {
|
|
return this.post<AuthSessionDTO>('/auth/login', params);
|
|
}
|
|
|
|
/** Get current session */
|
|
getSession(): Promise<AuthSessionDTO | null> {
|
|
return this.get<AuthSessionDTO | 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}`;
|
|
}
|
|
} |