50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
import { BaseApiClient } from '../base/BaseApiClient';
|
|
import { AuthSessionDTO } from '../../types/generated/AuthSessionDTO';
|
|
import { LoginParams } from '../../types/generated/LoginParams';
|
|
import { SignupParams } from '../../types/generated/SignupParams';
|
|
import { LoginWithIracingCallbackParams } from '../../types/generated/LoginWithIracingCallbackParams';
|
|
import { IracingAuthRedirectResult } from '../../types/generated/IracingAuthRedirectResult';
|
|
|
|
/**
|
|
* Auth API Client
|
|
*
|
|
* Handles all authentication-related API operations.
|
|
*/
|
|
export class AuthApiClient extends BaseApiClient {
|
|
/** Sign up with email */
|
|
signup(params: SignupParams): Promise<AuthSessionDTO> {
|
|
return this.post<AuthSessionDTO>('/auth/signup', params);
|
|
}
|
|
|
|
/** Login with email */
|
|
login(params: LoginParams): 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 */
|
|
startIracingAuthRedirect(returnTo?: string): Promise<IracingAuthRedirectResult> {
|
|
const query = returnTo ? `?returnTo=${encodeURIComponent(returnTo)}` : '';
|
|
return this.get<IracingAuthRedirectResult>(`/auth/iracing/start${query}`);
|
|
}
|
|
|
|
/** Login with iRacing callback */
|
|
loginWithIracingCallback(params: LoginWithIracingCallbackParams): Promise<AuthSessionDTO> {
|
|
const query = new URLSearchParams();
|
|
query.append('code', params.code);
|
|
query.append('state', params.state);
|
|
if (params.returnTo) {
|
|
query.append('returnTo', params.returnTo);
|
|
}
|
|
return this.get<AuthSessionDTO>(`/auth/iracing/callback?${query.toString()}`);
|
|
}
|
|
} |