fix: pass refresh_token in body when calling /auth/refresh
The refresh endpoint expects {"refresh_token":"..."} in the POST body,
but the frontend was sending an empty body (EOF error). Now stores the
refresh_token from login response and sends it on refresh requests.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
df0d490a42
commit
9ecf3c3179
@ -1,4 +1,4 @@
|
|||||||
import { http, setAccessToken } from './client';
|
import { http, setAccessToken, setRefreshToken } from './client';
|
||||||
import type { Profile, Company, UserRole } from '../types';
|
import type { Profile, Company, UserRole } from '../types';
|
||||||
|
|
||||||
export interface LoginRequest {
|
export interface LoginRequest {
|
||||||
@ -31,6 +31,7 @@ export const authApi = {
|
|||||||
login: async (data: LoginRequest) => {
|
login: async (data: LoginRequest) => {
|
||||||
const res = await http.post<LoginResponse>('/auth/login', data);
|
const res = await http.post<LoginResponse>('/auth/login', data);
|
||||||
setAccessToken(res.data.access_token);
|
setAccessToken(res.data.access_token);
|
||||||
|
setRefreshToken(res.data.refresh_token);
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ export const authApi = {
|
|||||||
logout: async () => {
|
logout: async () => {
|
||||||
await http.post('/auth/logout');
|
await http.post('/auth/logout');
|
||||||
setAccessToken(null);
|
setAccessToken(null);
|
||||||
|
setRefreshToken(null);
|
||||||
},
|
},
|
||||||
|
|
||||||
refresh: async () => {
|
refresh: async () => {
|
||||||
|
|||||||
@ -13,12 +13,17 @@ export interface PaginationParams {
|
|||||||
const API_BASE = '/api/v1';
|
const API_BASE = '/api/v1';
|
||||||
|
|
||||||
let accessToken: string | null = null;
|
let accessToken: string | null = null;
|
||||||
|
let refreshTokenValue: string | null = null;
|
||||||
let refreshPromise: Promise<boolean> | null = null;
|
let refreshPromise: Promise<boolean> | null = null;
|
||||||
|
|
||||||
export function setAccessToken(token: string | null) {
|
export function setAccessToken(token: string | null) {
|
||||||
accessToken = token;
|
accessToken = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setRefreshToken(token: string | null) {
|
||||||
|
refreshTokenValue = token;
|
||||||
|
}
|
||||||
|
|
||||||
export function getAccessToken(): string | null {
|
export function getAccessToken(): string | null {
|
||||||
return accessToken;
|
return accessToken;
|
||||||
}
|
}
|
||||||
@ -27,6 +32,8 @@ async function refreshToken(): Promise<boolean> {
|
|||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_BASE}/auth/refresh`, {
|
const res = await fetch(`${API_BASE}/auth/refresh`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ refresh_token: refreshTokenValue }),
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
});
|
});
|
||||||
if (!res.ok) return false;
|
if (!res.ok) return false;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user