This commit is contained in:
NotII
2025-03-24 17:18:27 +00:00
parent 43a3656233
commit 06984b53ef
2 changed files with 82 additions and 17 deletions

View File

@@ -6,17 +6,10 @@
* Get the authentication token from cookies or localStorage
*/
export function getAuthToken(): string | null {
const token = document.cookie
return 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;
}
/**
@@ -37,7 +30,7 @@ export async function logoutUser(): Promise<void> {
await fetch(`/api/auth/logout`, {
method: 'POST',
headers: {
'Authorization': token,
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
}).catch(err => {