feat(mvp): phase 3 - authentication system

Implement local auth flow: login, registration, logout, JWT access/refresh
tokens in HTTP-only cookies, hooks.server.ts middleware, guest mode support,
Superforms + Zod validation, and reusable auth/authorize middleware.
This commit is contained in:
2026-03-24 20:45:14 +03:00
parent f1b1aa5975
commit 2c001df322
19 changed files with 751 additions and 28 deletions
+22
View File
@@ -0,0 +1,22 @@
import { redirect } from '@sveltejs/kit';
import type { RequestEvent } from '@sveltejs/kit';
/**
* Reusable authentication check helper.
* Throws a redirect to /login if the user is not authenticated.
* Returns the authenticated user from event.locals.
*/
export function requireAuth(event: RequestEvent) {
const user = event.locals.user;
if (!user) {
throw redirect(302, '/login');
}
return user;
}
/**
* Check if the current request has an authenticated user without redirecting.
*/
export function isAuthenticated(event: RequestEvent): boolean {
return event.locals.user !== null;
}