@@ -4,39 +4,31 @@ definePageMeta({ layout: 'auth' })
44useSeoMeta ({ robots: ' noindex, nofollow' })
55
66const localePath = useLocalePath ()
7- const config = useRuntimeConfig ()
87
98onMounted (async () => {
10- const { data : session } = await authClient .useSession (useFetch )
11-
12- if (! session .value ) {
13- // Not logged in — just go to sign-up
14- await navigateTo (localePath (' /auth/sign-up' ), { replace: true })
15- return
16- }
17-
18- // Check if the user is in the demo org
19- const demoSlug = config .public .demoOrgSlug
20- if (! demoSlug ) {
21- // No demo slug configured — redirect to dashboard
22- await navigateTo (localePath (' /dashboard' ), { replace: true })
23- return
24- }
25-
26- // Await the active org — useActiveOrganization() is reactive and
27- // may not have resolved when read synchronously inside onMounted
28- const { data : org } = await authClient .organization .getFullOrganization ()
29- const isDemo = org ?.slug === demoSlug
30-
31- if (isDemo ) {
32- // Demo user — sign out and redirect to sign-up for a real account
33- await authClient .signOut ()
34- clearNuxtData ()
35- await navigateTo (localePath (' /auth/sign-up' ), { replace: true })
9+ try {
10+ // Server-side demo check — avoids client-side auth library quirks
11+ const { hasSession, isDemo } = await $fetch (' /api/auth/demo-check' )
12+
13+ if (! hasSession ) {
14+ window .location .href = localePath (' /auth/sign-up' )
15+ return
16+ }
17+
18+ if (isDemo ) {
19+ // Sign out the demo session via the auth API directly
20+ await $fetch (' /api/auth/sign-out' , { method: ' POST' , body: {} })
21+ // Hard navigate to clear all client-side state (Better Auth atoms, Nuxt caches)
22+ window .location .href = localePath (' /auth/sign-up' )
23+ }
24+ else {
25+ // Real user — go to dashboard
26+ window .location .href = localePath (' /dashboard' )
27+ }
3628 }
37- else {
38- // Real user — don't sign out, redirect to dashboard
39- await navigateTo ( localePath (' /dashboard ' ), { replace: true } )
29+ catch {
30+ // On any error, default to sign-up
31+ window . location . href = localePath (' /auth/sign-up ' )
4032 }
4133})
4234 </script >
0 commit comments