feat: sync api changes and fix auth-related bugs

Signed-off-by: Noa Virellia <noa@requiem.garden>
This commit is contained in:
2026-01-20 19:37:33 +08:00
parent a60a796345
commit 27ac4d9b4a
6 changed files with 109 additions and 35 deletions

View File

@@ -1,4 +1,4 @@
import axios from 'axios';
import { axiosClient, HEADER_API_VERSION } from './axios';
export function setToken(token: string) {
localStorage.setItem('token', token);
@@ -30,11 +30,11 @@ export function clearTokens() {
}
export async function doSetTokenByCode(code: string) {
const { data } = await axios.post<{ access_token: string; refresh_token: string }>('/api/v1/auth/token', { code });
const { data } = await axiosClient.post<{ access_token: string; refresh_token: string }>('/auth/token', { code }, { headers: HEADER_API_VERSION });
setToken(data.access_token);
setRefreshToken(data.refresh_token);
}
export async function doRefreshToken() {
return axios.post<{ access_token: string; refresh_token: string }>('/api/v1/auth/refresh', { refresh_token: getRefreshToken() });
return axiosClient.post<{ access_token: string; refresh_token: string }>('/auth/refresh', { refresh_token: getRefreshToken() }, { headers: HEADER_API_VERSION });
}