mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 19:04:23 +00:00
* fix(webui): allow reset-password route with token when stale auth exists * fix(webui): prevent 401 redirect to login on reset-password page
28 lines
757 B
TypeScript
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: '/',
|
|
})
|
|
}
|
|
},
|
|
})
|