31 lines
802 B
TypeScript
31 lines
802 B
TypeScript
|
|
// All authentication API calls in one place.
|
|
|
|
import { post } from "./api";
|
|
import type { LoginResponse } from "../types/auth";
|
|
|
|
export interface LoginPayload {
|
|
identity: string;
|
|
password: string;
|
|
}
|
|
|
|
export const authService = {
|
|
/**
|
|
* Authenticate a user with email / phone / username + password.
|
|
* Throws `ApiError` on network or credential failure.
|
|
*/
|
|
login: (payload: LoginPayload) =>
|
|
post<LoginResponse>("auth/login", payload),
|
|
|
|
/**
|
|
* Request a password reset email.
|
|
*/
|
|
forgotPassword: (email: string) =>
|
|
post<{ message: string }>("auth/forgot-password", { email }),
|
|
|
|
/**
|
|
* Confirm a password reset with a token.
|
|
*/
|
|
resetPassword: (token: string, newPassword: string) =>
|
|
post<{ message: string }>("auth/reset-password", { token, newPassword }),
|
|
}; |