mirror of
https://github.com/pupperpowell/bibdle.git
synced 2026-04-05 17:33:31 -04:00
Support authenticated users in stats and page loading
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user