fix
This commit is contained in:
@@ -6,10 +6,17 @@
|
||||
* Get the authentication token from cookies or localStorage
|
||||
*/
|
||||
export function getAuthToken(): string | null {
|
||||
return document.cookie
|
||||
const token = document.cookie
|
||||
.split('; ')
|
||||
.find(row => row.startsWith('Authorization='))
|
||||
?.split('=')[1] || localStorage.getItem('Authorization');
|
||||
|
||||
// If token exists but doesn't have Bearer prefix, add it
|
||||
if (token && !token.startsWith('Bearer ')) {
|
||||
return `Bearer ${token}`;
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,7 +37,7 @@ export async function logoutUser(): Promise<void> {
|
||||
await fetch(`/api/auth/logout`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Authorization': token,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}).catch(err => {
|
||||
|
||||
@@ -32,12 +32,13 @@ function getAuthToken(): string | null {
|
||||
function createApiHeaders(token?: string | null, customHeaders: Record<string, string> = {}): Headers {
|
||||
const headers = new Headers({
|
||||
'Content-Type': 'application/json',
|
||||
'accept': '*/*',
|
||||
...customHeaders
|
||||
});
|
||||
|
||||
const authToken = token || getAuthToken();
|
||||
if (authToken) {
|
||||
headers.set('Authorization', `Bearer ${authToken}`);
|
||||
headers.set('authorization', `Bearer ${authToken}`);
|
||||
}
|
||||
|
||||
return headers;
|
||||
@@ -59,6 +60,8 @@ export async function clientFetch<T = any>(url: string, options: RequestInit = {
|
||||
...options,
|
||||
headers,
|
||||
credentials: 'include',
|
||||
mode: 'cors',
|
||||
referrerPolicy: 'strict-origin-when-cross-origin'
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
|
||||
Reference in New Issue
Block a user