lazy load socket connection
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
const BASE_URL = process.env.API_BASE_URL || 'http://localhost:8080';
|
||||
|
||||
type ApiResponse<T> = {
|
||||
@@ -8,6 +6,10 @@ type ApiResponse<T> = {
|
||||
message?: string;
|
||||
};
|
||||
|
||||
const destroySession = async (): Promise<void> => {
|
||||
await fetch('/api/session', { method: 'DELETE' });
|
||||
};
|
||||
|
||||
export async function fetchServerAPI<T>(
|
||||
endpoint: string,
|
||||
token: string,
|
||||
@@ -28,7 +30,8 @@ export async function fetchServerAPI<T>(
|
||||
|
||||
if (!response.ok) {
|
||||
if (response.status == 401) {
|
||||
redirect('/logout');
|
||||
await destroySession();
|
||||
window.location.href = '/login';
|
||||
return { error: 'unauthorized' };
|
||||
}
|
||||
throw new Error(
|
||||
|
||||
Reference in New Issue
Block a user