fix(auth): редирект на portal по runtime /api/auth/config при 401
Docker / build (push) Failing after 20s
Docker / build (push) Failing after 20s
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
84cc800d54
commit
812aa614df
7 files changed
+144
-42
No files matched your search
@@ -2,23 +2,26 @@ import { Outlet, createFileRoute, redirect } from '@tanstack/react-router'
|
||||
import { snapshotQueryOptions } from '@/queries/snapshot'
|
||||
import {
|
||||
can,
|
||||
ensureAuthConfig,
|
||||
firstAllowedPath,
|
||||
getClaims,
|
||||
getToken,
|
||||
isAuthEnabled,
|
||||
permissionForPath,
|
||||
redirectToPortalLogin,
|
||||
} from '@/lib/auth'
|
||||
|
||||
export const Route = createFileRoute('/_auth')({
|
||||
beforeLoad: ({ location }) => {
|
||||
if (!isAuthEnabled()) return
|
||||
beforeLoad: async ({ location }) => {
|
||||
const cfg = await ensureAuthConfig()
|
||||
if (!cfg.required) return
|
||||
|
||||
const token = getToken()
|
||||
const claims = getClaims()
|
||||
if (!token || !claims) {
|
||||
redirectToPortalLogin(`${window.location.origin}/auth/callback`)
|
||||
throw new Error('Redirecting to auth portal')
|
||||
// Abort route load while browser navigates away
|
||||
await new Promise(() => {})
|
||||
return
|
||||
}
|
||||
if (!claims.apps.includes('vps')) {
|
||||
throw redirect({ to: '/' })
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { createFileRoute, redirect } from '@tanstack/react-router'
|
||||
import {
|
||||
ensureAuthConfig,
|
||||
firstAllowedPath,
|
||||
isAuthEnabled,
|
||||
parseHashToken,
|
||||
redirectToPortalLogin,
|
||||
setToken,
|
||||
} from '@/lib/auth'
|
||||
|
||||
export const Route = createFileRoute('/auth/callback')({
|
||||
beforeLoad: () => {
|
||||
if (!isAuthEnabled()) {
|
||||
throw redirect({ to: '/dashboard' })
|
||||
}
|
||||
beforeLoad: async () => {
|
||||
await ensureAuthConfig()
|
||||
const { accessToken } = parseHashToken(window.location.hash)
|
||||
if (!accessToken) {
|
||||
throw redirect({ to: '/' })
|
||||
redirectToPortalLogin(`${window.location.origin}/auth/callback`)
|
||||
await new Promise(() => {})
|
||||
return
|
||||
}
|
||||
setToken(accessToken)
|
||||
window.history.replaceState(null, '', '/auth/callback')
|
||||
|
||||
Reference in new issue
Block a user