Refine knowledge brain workflow
Align the brain prompts, graph view, and startup defaults with the latest phase 1 flow so local runs and navigation stay consistent.
This commit is contained in:
38
frontend/src/app/router/index.test.ts
Normal file
38
frontend/src/app/router/index.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createPinia, setActivePinia } from 'pinia'
|
||||
|
||||
const { apiGetMock } = vi.hoisted(() => ({
|
||||
apiGetMock: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api', () => ({
|
||||
default: {
|
||||
get: apiGetMock,
|
||||
post: vi.fn(),
|
||||
interceptors: {
|
||||
request: { use: vi.fn() },
|
||||
response: { use: vi.fn() },
|
||||
},
|
||||
},
|
||||
}))
|
||||
|
||||
describe('auth router guard', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
localStorage.clear()
|
||||
apiGetMock.mockReset()
|
||||
window.history.replaceState({}, '', '/')
|
||||
setActivePinia(createPinia())
|
||||
})
|
||||
|
||||
it('redirects to /login when a stored token fails validation during startup', async () => {
|
||||
localStorage.setItem('access_token', 'stale-token')
|
||||
apiGetMock.mockRejectedValueOnce({ response: { status: 401 } })
|
||||
|
||||
const { default: router } = await import('./index')
|
||||
|
||||
await router.push('/chat')
|
||||
|
||||
expect(router.currentRoute.value.fullPath).toBe('/login')
|
||||
})
|
||||
})
|
||||
@@ -7,8 +7,11 @@ const router = createRouter({
|
||||
routes,
|
||||
})
|
||||
|
||||
router.beforeEach((to, _from, next) => {
|
||||
router.beforeEach(async (to, _from, next) => {
|
||||
const auth = useAuthStore()
|
||||
|
||||
await auth.ensureAuthReady()
|
||||
|
||||
if (to.meta.requiresAuth && !auth.isAuthenticated) {
|
||||
next('/login')
|
||||
} else if (to.meta.guest && auth.isAuthenticated) {
|
||||
|
||||
Reference in New Issue
Block a user