@@ -3,13 +3,36 @@ definePageMeta({ layout: 'auth' })
33
44useSeoMeta ({ robots: ' noindex, nofollow' })
55
6- onMounted (() => {
7- // Full browser navigation to the server endpoint. The server checks
8- // the session, destroys it if it belongs to the demo org, clears
9- // auth cookies via Set-Cookie headers, and returns a 302 redirect
10- // to either /auth/sign-up or /dashboard. Using native navigation
11- // (not $fetch) guarantees the browser processes Set-Cookie headers.
12- window .location .replace (' /api/auth/demo-fresh-signup' )
6+ const localePath = useLocalePath ()
7+
8+ onMounted (async () => {
9+ try {
10+ // Check if there's an existing session and whether it's a demo org
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 using the Better Auth client SDK — the same method
20+ // that works in AppTopBar. This properly handles CSRF tokens,
21+ // cookie clearing, and internal auth state, unlike raw $fetch
22+ // to the sign-out endpoint which bypasses all of that.
23+ await authClient .signOut ()
24+ clearNuxtData ()
25+ // Hard navigate to fully reset all client-side state
26+ window .location .href = localePath (' /auth/sign-up' )
27+ }
28+ else {
29+ // Real user with a non-demo account — go to dashboard
30+ window .location .href = localePath (' /dashboard' )
31+ }
32+ }
33+ catch {
34+ window .location .href = localePath (' /auth/sign-up' )
35+ }
1336})
1437 </script >
1538
0 commit comments