45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { BaseApiClient } from '../base/BaseApiClient';
|
|
import { AuthSessionDTO } from '../../types/generated/AuthSessionDTO';
|
|
import { LoginParamsDTO } from '../../types/generated/LoginParamsDTO';
|
|
import { SignupParamsDTO } from '../../types/generated/SignupParamsDTO';
|
|
import { ForgotPasswordDTO } from '../../types/generated/ForgotPasswordDTO';
|
|
import { ResetPasswordDTO } from '../../types/generated/ResetPasswordDTO';
|
|
|
|
/**
|
|
* 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.request<AuthSessionDTO | null>('GET', '/auth/session', undefined, {
|
|
allowUnauthenticated: true,
|
|
});
|
|
}
|
|
|
|
/** Logout */
|
|
logout(): Promise<void> {
|
|
return this.post<void>('/auth/logout', {});
|
|
}
|
|
|
|
/** Forgot password - send reset link */
|
|
forgotPassword(params: ForgotPasswordDTO): Promise<{ message: string; magicLink?: string }> {
|
|
return this.post<{ message: string; magicLink?: string }>('/auth/forgot-password', params);
|
|
}
|
|
|
|
/** Reset password with token */
|
|
resetPassword(params: ResetPasswordDTO): Promise<{ message: string }> {
|
|
return this.post<{ message: string }>('/auth/reset-password', params);
|
|
}
|
|
} |