fix(auth): восстанавливать раздел и фильтры после входа Portal

This commit is contained in:
Denozordec committed 2026-10-13 16:09:27 +07:00
1 parent 199910eceb
commit 46de87e213
15 files changed
+275 -17

No files matched your search

+12 -3
View File
@@ -5,15 +5,18 @@ import { useRouter } from "next/navigation"
import {
clearPortalHandoffFlag,
clearToken,
can,
ensureAuthConfig,
firstAllowedPath,
getClaims,
getToken,
parseHashToken,
permissionForPath,
redirectToPortalLogin,
redirectToPortalLoginInteractive,
setToken,
} from "@/lib/auth"
import { permittedAuthReturnPath } from "@/lib/auth-return-path"
export default function AuthCallbackPage() {
const router = useRouter()
@@ -28,6 +31,10 @@ export default function AuthCallbackPage() {
const params = new URLSearchParams(window.location.search)
const error = params.get("error")
const returnPath = () => permittedAuthReturnPath(params.get("next"), pathname => {
const permission = permissionForPath(pathname)
return !permission || can(permission)
}, firstAllowedPath())
if (error === "sso_loop" || error === "jwt_rejected") {
redirectToPortalLoginInteractive()
return
@@ -62,7 +69,7 @@ export default function AuthCallbackPage() {
/* ignore network — proceed */
}
const next = firstAllowedPath()
const next = returnPath()
if (next === "/access-denied") {
router.replace("/access-denied")
return
@@ -77,11 +84,13 @@ export default function AuthCallbackPage() {
router.replace("/access-denied")
return
}
router.replace(firstAllowedPath())
router.replace(returnPath())
return
}
const ok = redirectToPortalLogin(`${window.location.origin}/auth/callback`)
const callback = new URL(`${window.location.origin}/auth/callback`)
if (params.get("next")) callback.searchParams.set("next", params.get("next")!)
const ok = redirectToPortalLogin(callback.toString())
if (!ok) redirectToPortalLoginInteractive()
})()