41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import axios from 'axios'
|
|
import { getRuntimeConfig } from './runtime-config'
|
|
import type { AuthSession } from './auth-storage'
|
|
|
|
export type LoginPayload = { email: string; password: string }
|
|
|
|
type LoginResponse = {
|
|
accessToken: string
|
|
refreshToken: string
|
|
tokenType: string
|
|
user: { id: string; email: string }
|
|
}
|
|
|
|
type RefreshResponse = {
|
|
accessToken: string
|
|
refreshToken: string
|
|
tokenType: string
|
|
}
|
|
|
|
function centerClient() {
|
|
const cfg = getRuntimeConfig()
|
|
return axios.create({
|
|
baseURL: cfg.centerApiBase,
|
|
timeout: 10000,
|
|
})
|
|
}
|
|
|
|
export async function loginCenter(payload: LoginPayload): Promise<AuthSession> {
|
|
const res = await centerClient().post<LoginResponse>('/auth/login', payload)
|
|
return res.data
|
|
}
|
|
|
|
export async function refreshCenter(refreshToken: string): Promise<RefreshResponse> {
|
|
const res = await centerClient().post<RefreshResponse>('/auth/refresh', { refreshToken })
|
|
return res.data
|
|
}
|
|
|
|
export async function logoutCenter(refreshToken: string): Promise<void> {
|
|
await centerClient().post('/auth/logout', { refreshToken })
|
|
}
|