feat(frontend): implement center auth session flow with route guard

This commit is contained in:
root
2026-05-12 15:09:06 +00:00
parent 6219fbbcfe
commit d718128f89
12 changed files with 269 additions and 4 deletions

View File

@@ -0,0 +1,40 @@
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 })
}