diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index b9c05d2..aa43951 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -4,7 +4,17 @@ export const API_URL = env.PUBLIC_API_URL || 'http://localhost:8000'; // Helper to get token from localStorage export function getToken(): string | null { - return localStorage.getItem('token'); + const tokenData = localStorage.getItem('token'); + if (tokenData) { + const { value, expiresAt } = JSON.parse(tokenData); + if (Date.now() > expiresAt) { + localStorage.removeItem('token'); + location.reload(); + return null; + } + return value; + } + return null; } // Helper to add Authorization header if token exists diff --git a/frontend/src/routes/login/+page.svelte b/frontend/src/routes/login/+page.svelte index 28cabc9..a20958d 100644 --- a/frontend/src/routes/login/+page.svelte +++ b/frontend/src/routes/login/+page.svelte @@ -30,7 +30,11 @@ } const data = await response.json(); - localStorage.setItem('token', data.access_token); + const expirationTime = Date.now() + 60 * 60 * 1000; // 60 minutes in milliseconds + localStorage.setItem( + 'token', + JSON.stringify({ value: data.access_token, expiresAt: expirationTime }) + ); goto('/').then(() => location.reload()); } catch (err) { loginError = 'Network error - ' + err; diff --git a/frontend/src/routes/notifications/[subscription_id]/+page.svelte b/frontend/src/routes/notifications/[subscription_id]/+page.svelte index d085d37..403b4b0 100644 --- a/frontend/src/routes/notifications/[subscription_id]/+page.svelte +++ b/frontend/src/routes/notifications/[subscription_id]/+page.svelte @@ -122,6 +122,11 @@