aboutsummaryrefslogtreecommitdiffstats
path: root/src/hooks.server.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-04 23:06:35 -0800
committerAdam Soltys <[email protected]>2026-03-04 23:06:35 -0800
commite5f37b003d93a17c2a9958697269b2d3228d8830 (patch)
treee2c3a3c4d1bec48d323e830f5be35d5832845a9a /src/hooks.server.ts
parente6882c6a8987e23215a2538b242431ae603c7101 (diff)
downloadcoinos-ui-e5f37b003d93a17c2a9958697269b2d3228d8830.tar.gz
coinos-ui-e5f37b003d93a17c2a9958697269b2d3228d8830.zip
tuning
Diffstat (limited to 'src/hooks.server.ts')
-rw-r--r--src/hooks.server.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/hooks.server.ts b/src/hooks.server.ts
index fcb1d461..7acb2a43 100644
--- a/src/hooks.server.ts
+++ b/src/hooks.server.ts
@@ -1,5 +1,6 @@
import { ipStore } from "$lib/server/ip";
import { setIpGetter } from "$lib/utils";
+import { redirect } from "@sveltejs/kit";
import type { Handle } from "@sveltejs/kit";
setIpGetter(() => ipStore.getStore());
@@ -17,6 +18,26 @@ export const handle: Handle = async ({ event, resolve }) => {
}
}
+ // Sync aid cookie from URL params
+ try {
+ const aid = event.url.searchParams.get("aid");
+ if (aid) event.cookies.set("aid", aid, { path: "/", maxAge: 86400, httpOnly: false });
+ } catch {}
+
+
+ // Auth check for (app) routes
+ const isAppRoute = event.route.id?.startsWith("/(app)");
+ const token = event.cookies.get("token");
+ const { pathname } = event.url;
+ const isSweep = pathname.match(/^\/fund\/[^/]+\/sweep/);
+ const isLogout = pathname === "/logout";
+ if (isLogout) {
+ // Clear token before layout load to prevent infinite redirect loops
+ event.cookies.set("token", "", { expires: new Date(0), path: "/" });
+ } else if (isAppRoute && !token && !isSweep) {
+ redirect(307, "/login");
+ }
+
return ipStore.run(ip, async () => {
const response = await resolve(event);
const { pathname } = event.url;