refactor: quality workflow, docs, tests
This commit is contained in:
parent
a9caf36b01
commit
68ace0a858
27 changed files with 758 additions and 330 deletions
|
|
@ -21,23 +21,30 @@ export function LoginPageClient() {
|
|||
const { data: session, isPending } = useSession()
|
||||
const callbackUrl = searchParams?.get("callbackUrl") ?? undefined
|
||||
const [isHydrated, setIsHydrated] = useState(false)
|
||||
const sessionUser = session?.user
|
||||
const userId = sessionUser?.id ?? null
|
||||
const normalizedRole = sessionUser?.role ? sessionUser.role.toLowerCase() : null
|
||||
const persona = typeof sessionUser?.machinePersona === "string" ? sessionUser.machinePersona.toLowerCase() : null
|
||||
|
||||
useEffect(() => {
|
||||
if (isPending) return
|
||||
if (!session?.user) return
|
||||
const role = (session.user.role ?? "").toLowerCase()
|
||||
const persona = (session.user as any).machinePersona
|
||||
? String((session.user as any).machinePersona).toLowerCase()
|
||||
: null
|
||||
if (!userId) return
|
||||
const defaultDest =
|
||||
role === "machine"
|
||||
normalizedRole === "machine"
|
||||
? persona === "manager"
|
||||
? "/dashboard"
|
||||
: "/portal/tickets"
|
||||
: "/dashboard"
|
||||
const destination = callbackUrl ?? defaultDest
|
||||
router.replace(destination)
|
||||
}, [callbackUrl, isPending, router, session?.user])
|
||||
}, [
|
||||
callbackUrl,
|
||||
isPending,
|
||||
normalizedRole,
|
||||
persona,
|
||||
router,
|
||||
userId,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
setIsHydrated(true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue