aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/hooks.server.js
diff options
context:
space:
mode:
authorzwlucas <lucas.fariamo08@gmail.com>2026-05-29 18:57:37 +0000
committerzwlucas <lucas.fariamo08@gmail.com>2026-05-29 18:57:37 +0000
commit6cc0bfd1d79074df790272b8091b1f0226d14283 (patch)
treecab18b0f708cf3b0eaeeeb98e2cf81459365b33e /frontend/src/hooks.server.js
downloadyaum-6cc0bfd1d79074df790272b8091b1f0226d14283.tar.gz
yaum-6cc0bfd1d79074df790272b8091b1f0226d14283.zip
feat: upload project
Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
Diffstat (limited to 'frontend/src/hooks.server.js')
-rw-r--r--frontend/src/hooks.server.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/frontend/src/hooks.server.js b/frontend/src/hooks.server.js
new file mode 100644
index 0000000..39c89e9
--- /dev/null
+++ b/frontend/src/hooks.server.js
@@ -0,0 +1,31 @@
+import { redirect } from '@sveltejs/kit';
+
+const API = 'http://localhost:8080/api';
+
+const PUBLIC_PREFIXES = ['/_app', '/api'];
+
+export async function handle({ event, resolve }) {
+ const isStatic = PUBLIC_PREFIXES.some((p) => event.url.pathname.startsWith(p));
+ const isLogin = event.url.pathname === '/login';
+ const isPublic = event.url.pathname === '/' || event.url.pathname.startsWith('/status/');
+
+ if (isStatic || isLogin || isPublic) {
+ return resolve(event);
+ }
+
+ if (event.url.pathname.startsWith('/admin')) {
+ const token = event.cookies.get('auth_token');
+ if (!token) {
+ throw redirect(302, '/login');
+ }
+ const res = await fetch(`${API}/auth/verify`, {
+ headers: { Authorization: `Bearer ${token}` }
+ });
+ if (!res.ok) {
+ throw redirect(302, '/login');
+ }
+ event.locals.token = token;
+ }
+
+ return resolve(event);
+}