update logout method

This commit is contained in:
Fran Jurmanović
2025-09-14 21:27:41 +02:00
parent e6b7ec7401
commit 4bc74f26d1
5 changed files with 12 additions and 14 deletions

View File

@@ -1,13 +1,5 @@
import { cookies } from 'next/headers';
import { redirect } from 'next/navigation';
export async function clearAuthAndRedirect(to = '/login') {
const c = await cookies();
c.delete('session');
c.delete('refresh');
redirect(to);
}
const BASE_URL = process.env.API_BASE_URL || 'http://localhost:8080';
type ApiResponse<T> = {
@@ -35,7 +27,7 @@ export async function fetchServerAPI<T>(
if (!response.ok) {
if (response.status == 401) {
clearAuthAndRedirect();
redirect('/logout');
return { error: 'unauthorized' };
}
throw new Error(