quality / changes (push) Successful in 5s
quality / api (push) Skipped
quality / commitlint (push) Skipped
quality / docker-check (push) Skipped
CD / update-wiki (push) Successful in 5s
quality / web (push) Successful in 57s
CD / quality (push) Successful in 1m9s
CD / publish (push) Successful in 1m39s
- Introduced a new Access Denied route to handle unauthorized access. - Updated routing logic to redirect to the Access Denied page when necessary. - Enhanced authentication checks to prevent infinite redirect loops and improve user experience. - Adjusted API client to handle JWT rejection scenarios more gracefully.
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
import { createRootRouteWithContext, Outlet, redirect } from '@tanstack/react-router'
|
|
import type { QueryClient } from '@tanstack/react-query'
|
|
import {
|
|
ensureAuthConfig,
|
|
getClaims,
|
|
getToken,
|
|
redirectToPortalLogin,
|
|
} from '@/lib/auth'
|
|
|
|
export interface RouterContext {
|
|
queryClient: QueryClient
|
|
}
|
|
|
|
export const Route = createRootRouteWithContext<RouterContext>()({
|
|
component: () => <Outlet />,
|
|
beforeLoad: async ({ location }) => {
|
|
const isLogin = location.pathname === '/login'
|
|
const isCallback = location.pathname === '/auth/callback'
|
|
const isAccessDenied = location.pathname === '/access-denied'
|
|
if (isCallback || isAccessDenied) return
|
|
|
|
const cfg = await ensureAuthConfig()
|
|
const token = getToken()
|
|
const claims = getClaims()
|
|
|
|
if (cfg.required) {
|
|
if (isLogin) {
|
|
const ok = redirectToPortalLogin(
|
|
`${window.location.origin}/auth/callback`,
|
|
)
|
|
if (!ok) {
|
|
throw redirect({
|
|
to: '/auth/callback',
|
|
search: { error: 'sso_loop' },
|
|
})
|
|
}
|
|
await new Promise(() => {})
|
|
return
|
|
}
|
|
if (!token || !claims) {
|
|
const ok = redirectToPortalLogin(
|
|
`${window.location.origin}/auth/callback`,
|
|
)
|
|
if (!ok) {
|
|
throw redirect({
|
|
to: '/auth/callback',
|
|
search: { error: 'sso_loop' },
|
|
})
|
|
}
|
|
await new Promise(() => {})
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// Local auth mode (AUTH_REQUIRED=false)
|
|
if (!token && !isLogin) {
|
|
throw redirect({ to: '/login' })
|
|
}
|
|
if (token && isLogin) {
|
|
throw redirect({ to: '/' })
|
|
}
|
|
},
|
|
})
|