diff --git a/src/api/auth.ts b/src/api/auth.ts index eef2a3e..4a151e8 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -1,4 +1,4 @@ -import { http, setAccessToken } from './client'; +import { http, setAccessToken, setRefreshToken } from './client'; import type { Profile, Company, UserRole } from '../types'; export interface LoginRequest { @@ -31,6 +31,7 @@ export const authApi = { login: async (data: LoginRequest) => { const res = await http.post('/auth/login', data); setAccessToken(res.data.access_token); + setRefreshToken(res.data.refresh_token); return res.data; }, @@ -40,6 +41,7 @@ export const authApi = { logout: async () => { await http.post('/auth/logout'); setAccessToken(null); + setRefreshToken(null); }, refresh: async () => { diff --git a/src/api/client.ts b/src/api/client.ts index ac87954..8f09b2c 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -13,12 +13,17 @@ export interface PaginationParams { const API_BASE = '/api/v1'; let accessToken: string | null = null; +let refreshTokenValue: string | null = null; let refreshPromise: Promise | null = null; export function setAccessToken(token: string | null) { accessToken = token; } +export function setRefreshToken(token: string | null) { + refreshTokenValue = token; +} + export function getAccessToken(): string | null { return accessToken; } @@ -27,6 +32,8 @@ async function refreshToken(): Promise { try { const res = await fetch(`${API_BASE}/auth/refresh`, { method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ refresh_token: refreshTokenValue }), credentials: 'include', }); if (!res.ok) return false;