mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-27 18:57:09 +00:00
Initial commit: Sencho V1 complete with Auth and Dockerization
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
const API_BASE = '/api';
|
||||
|
||||
export async function apiFetch(
|
||||
endpoint: string,
|
||||
options: RequestInit = {}
|
||||
): Promise<Response> {
|
||||
const url = `${API_BASE}${endpoint}`;
|
||||
const defaultOptions: RequestInit = {
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers,
|
||||
},
|
||||
};
|
||||
|
||||
const response = await fetch(url, { ...defaultOptions, ...options });
|
||||
|
||||
if (response.status === 401) {
|
||||
// Clear auth state and redirect to login
|
||||
window.location.href = '/';
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export { API_BASE };
|
||||
Reference in New Issue
Block a user