Files
shumai/packages/webui/routes/reset-password.tsx
T
Yiling-J 19eed521ae fix(webui): prevent unwanted redirects to login on reset-password page (#487)
* fix(webui): allow reset-password route with token when stale auth exists

* fix(webui): prevent 401 redirect to login on reset-password page
2026-10-21 12:12:25 +08:00

28 lines
757 B
TypeScript

import { createFileRoute, redirect } from '@tanstack/react-router'
import { useAuthStore } from '@/ui/stores/auth'
import { z } from 'zod'
const searchSchema = z.object({
token: z.string().catch(''),
})
export const Route = createFileRoute('/reset-password')({
validateSearch: (search) => searchSchema.parse(search),
beforeLoad: ({ search }) => {
// If a reset token is present in the URL, prioritize password recovery
// and clear any stale local auth state so the user can cleanly reset and log in
if (search.token) {
if (useAuthStore.getState().user) {
useAuthStore.getState().clearAuth()
}
return
}
if (useAuthStore.getState().user) {
throw redirect({
to: '/',
})
}
},
})