refactor: centralize access token handling in cookies and improve related functions

- Introduced utility functions for managing access tokens in cookies, including setting, getting, and clearing tokens.
- Updated various components and server routes to utilize the new access token functions for better consistency and maintainability.
- Removed redundant cookie handling code across the application, streamlining the authentication process.
This commit is contained in:
2026-05-01 21:30:52 -05:00
parent 2fbd476145
commit a5b378ccff
31 changed files with 256 additions and 91 deletions

View File

@@ -1,6 +1,7 @@
import type { Handle } from '@sveltejs/kit';
import { paraglideMiddleware } from '$lib/paraglide/server';
import { sequence } from '@sveltejs/kit/hooks';
import { getAccessTokenFromCookies } from '$lib/server/access-token-cookie';
const handleParaglide: Handle = ({ event, resolve }) => paraglideMiddleware(event.request, ({ request, locale }) => {
event.request = request;
@@ -12,7 +13,7 @@ const handleParaglide: Handle = ({ event, resolve }) => paraglideMiddleware(even
const handleAuth: Handle = async ({ event, resolve }) => {
// Obtener el token de las cookies
const token = event.cookies.get('access_token');
const token = getAccessTokenFromCookies(event.cookies);
// Agregar el token a los locals para que esté disponible en toda la app
event.locals.token = token || null;