mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 19:04:23 +00:00
* feat(mcp): add OAuth 2.1 support with dynamic client registration * feat(api): alias bare oauth-authorization-server discovery endpoint * fix(auth): preserve user session on OAuth sign-in redirect to consent
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { createFileRoute, redirect } from '@tanstack/react-router'
|
|
import { getAuthSession } from '@/ui/lib/auth-client'
|
|
import { useAuthStore } from '@/ui/stores/auth'
|
|
import { z } from 'zod'
|
|
|
|
const searchSchema = z
|
|
.object({
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
client_id: z.string().optional().catch(''),
|
|
scope: z.string().optional().catch(''),
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
redirect_uri: z.string().optional().catch(''),
|
|
})
|
|
.passthrough()
|
|
|
|
export const Route = createFileRoute('/consent')({
|
|
validateSearch: (search) => searchSchema.parse(search),
|
|
beforeLoad: async () => {
|
|
let currentUser = useAuthStore.getState().user
|
|
if (!currentUser) {
|
|
try {
|
|
const sessionData = await getAuthSession()
|
|
if (sessionData?.data?.user) {
|
|
useAuthStore.getState().setUser(sessionData.data.user)
|
|
currentUser = sessionData.data.user
|
|
}
|
|
} catch {
|
|
// Fall through to redirect
|
|
}
|
|
}
|
|
|
|
if (!currentUser) {
|
|
throw redirect({
|
|
to: '/login',
|
|
})
|
|
}
|
|
},
|
|
})
|