samar m commited on
Commit
c5d3374
·
1 Parent(s): 09a5796

fix: rename internal refresh fn to avoid confusion, add Content-Type header

Browse files
Files changed (1) hide show
  1. frontend/src/api/client.ts +5 -2
frontend/src/api/client.ts CHANGED
@@ -2,9 +2,12 @@ import { useAuthStore } from '../store/authStore'
2
 
3
  const API_BASE = ''
4
 
5
- async function refreshToken(): Promise<boolean> {
6
  const res = await fetch(`${API_BASE}/api/auth/refresh`, {
7
  method: 'POST',
 
 
 
8
  credentials: 'include',
9
  })
10
  if (!res.ok) return false
@@ -28,7 +31,7 @@ export async function apiFetch(path: string, options: RequestInit = {}): Promise
28
  })
29
 
30
  if (res.status === 401) {
31
- const refreshed = await refreshToken()
32
  if (!refreshed) {
33
  useAuthStore.getState().clearAuth()
34
  window.location.href = '/login'
 
2
 
3
  const API_BASE = ''
4
 
5
+ async function _silentRefresh(): Promise<boolean> {
6
  const res = await fetch(`${API_BASE}/api/auth/refresh`, {
7
  method: 'POST',
8
+ headers: {
9
+ 'Content-Type': 'application/json',
10
+ },
11
  credentials: 'include',
12
  })
13
  if (!res.ok) return false
 
31
  })
32
 
33
  if (res.status === 401) {
34
+ const refreshed = await _silentRefresh()
35
  if (!refreshed) {
36
  useAuthStore.getState().clearAuth()
37
  window.location.href = '/login'