Skip to content

Commit e1f20a3

Browse files
committed
[setup] check status once per page load
1 parent 20b6de1 commit e1f20a3

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

web/src/App.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
<script setup lang="ts">
22
import { onMounted, ref } from 'vue'
3-
import { useRoute } from 'vue-router'
3+
import { useRouter, useRoute } from 'vue-router'
44
import { useAuthStore } from '@/stores/auth'
55
import AppSidebar from '@/components/AppSidebar.vue'
66
import AppLayoutHeader from '@/components/AppLayoutHeader.vue'
77
import DialogContainer from '@/components/DialogContainer.vue'
88
import { SidebarInset, SidebarProvider } from '@/components/ui/sidebar'
99
import { TooltipProvider } from '@/components/ui/tooltip'
10+
import { client } from '@/client/client.gen'
1011
1112
import 'vue-sonner/style.css'
1213
import { Toaster } from '@/components/ui/sonner'
1314
1415
const authStore = useAuthStore()
16+
const router = useRouter()
1517
const route = useRoute()
1618
const isCheckingAuth = ref(true)
19+
const isCheckingSetup = ref(true)
20+
const needsSetup = ref(false)
1721
1822
onMounted(async () => {
23+
// Check setup status once on page load
24+
try {
25+
const response = await client.get({ url: '/v1/setup/status' })
26+
needsSetup.value = !(response as any).data.initialized
27+
if (needsSetup.value && route.path !== '/setup') {
28+
router.push('/setup')
29+
}
30+
} catch {
31+
// If setup check fails, assume initialized
32+
needsSetup.value = false
33+
}
34+
isCheckingSetup.value = false
35+
1936
// Rehydrate auth token from localStorage
2037
if (!authStore.token) {
2138
await authStore.rehydrate()
@@ -28,7 +45,7 @@ onMounted(async () => {
2845
<TooltipProvider>
2946
<Toaster position="top-center" />
3047
<DialogContainer />
31-
<div v-if="isCheckingAuth" class="flex min-h-svh items-center justify-center">
48+
<div v-if="isCheckingAuth || isCheckingSetup" class="flex min-h-svh items-center justify-center">
3249
<div class="text-muted-foreground">Loading...</div>
3350
</div>
3451
<router-view v-else-if="route.meta.public" />

web/src/router/index.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createRouter, createWebHistory } from 'vue-router'
22
import { useAuthStore } from '@/stores/auth'
3-
import { client } from '@/client/client.gen'
43

54
const router = createRouter({
65
history: createWebHistory(import.meta.env.BASE_URL),
@@ -91,19 +90,6 @@ const router = createRouter({
9190
],
9291
})
9392

94-
// Check setup status
95-
async function checkSetupStatus(): Promise<boolean> {
96-
try {
97-
const response = await client.get<{ initialized: boolean }>({
98-
url: '/v1/setup/status',
99-
})
100-
return (response as any).data.initialized
101-
} catch {
102-
// If setup check fails, assume initialized (safer default)
103-
return true
104-
}
105-
}
106-
10793
router.beforeEach(async (to) => {
10894
const auth = useAuthStore()
10995

@@ -112,20 +98,7 @@ router.beforeEach(async (to) => {
11298
await auth.rehydrate()
11399
}
114100

115-
// Check if setup is complete
116-
const isInitialized = await checkSetupStatus()
117-
118-
// If not initialized, redirect everything to setup (except setup page itself)
119-
if (!isInitialized && to.path !== '/setup') {
120-
return { path: '/setup' }
121-
}
122-
123-
// If initialized, block setup page
124-
if (isInitialized && to.path === '/setup') {
125-
return { path: '/login' }
126-
}
127-
128-
// Public routes allowed
101+
// Public routes (login, setup, auth callback)
129102
if (to.meta.public) {
130103
return true
131104
}

0 commit comments

Comments
 (0)