fix logout issues

This commit is contained in:
Fran Jurmanović
2025-09-22 22:49:15 +02:00
parent c005090ab1
commit 6563396a83
4 changed files with 23 additions and 10 deletions

View File

@@ -45,3 +45,7 @@ export async function loginAction(prevState: LoginResult, formData: FormData) {
export async function logoutAction() {
await logout();
}
export async function clearExpiredSessionAction() {
await logout();
}

View File

@@ -6,11 +6,7 @@ type ApiResponse<T> = {
message?: string;
};
import { logout } from '@/lib/auth/server';
const destroySession = async (): Promise<void> => {
await logout();
};
import { redirect } from 'next/navigation';
export async function fetchServerAPI<T>(
endpoint: string,
@@ -32,8 +28,7 @@ export async function fetchServerAPI<T>(
if (!response.ok) {
if (response.status == 401) {
await destroySession();
return { error: 'unauthorized' };
redirect('/login?expired=true');
}
throw new Error(
`API Error: ${response.statusText} - ${method} - ${BASE_URL}${endpoint} - ${token}`