resolve logout issues

This commit is contained in:
Fran Jurmanović
2025-09-22 20:45:02 +02:00
parent 6aeb654abf
commit c005090ab1
7 changed files with 36 additions and 39 deletions

View File

@@ -17,9 +17,6 @@ const getSession = async (): Promise<SessionData | null> => {
}
return null;
};
const destroySession = async (): Promise<void> => {
await fetch('/api/session', { method: 'DELETE' });
};
export async function fetchClientAPI<T>(
endpoint: string,
@@ -52,7 +49,6 @@ export async function fetchClientAPI<T>(
if (!response.ok) {
if (response.status === 401) {
await destroySession();
window.location.href = '/login';
return { error: 'unauthorized' };
}

View File

@@ -6,8 +6,10 @@ type ApiResponse<T> = {
message?: string;
};
import { logout } from '@/lib/auth/server';
const destroySession = async (): Promise<void> => {
await fetch('/api/session', { method: 'DELETE' });
await logout();
};
export async function fetchServerAPI<T>(
@@ -31,7 +33,6 @@ export async function fetchServerAPI<T>(
if (!response.ok) {
if (response.status == 401) {
await destroySession();
window.location.href = '/login';
return { error: 'unauthorized' };
}
throw new Error(