This commit is contained in:
NotII
2025-03-24 16:53:19 +00:00
parent 11d32a2c46
commit 8534ed040c
3 changed files with 15 additions and 13 deletions

View File

@@ -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 => {