feat: Add JWT authentication to backend, configure frontend API client, fix streak layout

This commit is contained in:
2026-09-23 12:11:44 +05:30
parent ea03846b9c
commit a3e430cb67
27 changed files with 210 additions and 120 deletions

27
src/lib/apiClient.ts Normal file
View File

@@ -0,0 +1,27 @@
export async function fetchWithAuth(url: string, options: RequestInit = {}): Promise<Response> {
const isServer = typeof window === 'undefined';
if (isServer) {
// If we're on the server-side, we should pass along headers from next/headers
// or just let it fall back to standard fetch if no auth is needed for server-side fetches.
// For this app, most data fetching seems to be client-side.
return fetch(url, options);
}
// Get token from localStorage
const token = localStorage.getItem('active_session_token');
// Prepare headers
const headers = new Headers(options.headers || {});
// Apply token if it exists
if (token) {
headers.set('Authorization', `Bearer ${token}`);
}
// Perform fetch with updated headers
return fetch(url, {
...options,
headers,
});
}