24 lines
588 B
TypeScript
24 lines
588 B
TypeScript
|
|
import request from '@/api/request'
|
||
|
|
|
||
|
|
/** Shape of a successful POST /api/auth/login response. */
|
||
|
|
export interface LoginResponse {
|
||
|
|
token: string
|
||
|
|
expiresIn: string
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* POST /api/auth/login with username + password.
|
||
|
|
* Throws a normalized {@link ApiError} (from the response interceptor) on
|
||
|
|
* failure — e.g. status 401 with message "invalid credentials".
|
||
|
|
*/
|
||
|
|
export async function loginApi(
|
||
|
|
username: string,
|
||
|
|
password: string,
|
||
|
|
): Promise<LoginResponse> {
|
||
|
|
const { data } = await request.post<LoginResponse>('/auth/login', {
|
||
|
|
username,
|
||
|
|
password,
|
||
|
|
})
|
||
|
|
return data
|
||
|
|
}
|