Support authenticated users in stats and page loading

This commit is contained in:
George Powell
2026-02-05 17:46:53 -05:00
parent 86f81cf9dd
commit 96024d5048
3 changed files with 35 additions and 11 deletions

View File

@@ -13,6 +13,8 @@
interface PageData {
stats: UserStats | null;
error?: string;
user?: any;
session?: any;
}
let { data }: { data: PageData } = $props();
@@ -31,14 +33,22 @@
}
onMount(async () => {
const url = new URL(window.location.href);
const hasUserId = url.searchParams.get('userId');
// If user is authenticated, no need to check for anonymousId
if (data.user || hasUserId) {
loading = false;
return;
}
// For anonymous users, ensure anonymousId is in URL
const anonymousId = getOrCreateAnonymousId();
if (!anonymousId) {
goto("/");
return;
}
// If no anonymousId in URL, redirect with it
const url = new URL(window.location.href);
if (!url.searchParams.get('anonymousId')) {
url.searchParams.set('anonymousId', anonymousId);
goto(url.pathname + url.search);