feat(auth): update login routes and add WxWork login callback handling

This commit is contained in:
mlogclub
2026-04-24 11:35:29 +08:00
parent 5fa30d29ef
commit 7889ecb0d2
8 changed files with 22 additions and 15 deletions
+10 -4
View File
@@ -1,7 +1,7 @@
"use client"
import { Loader2Icon } from "lucide-react"
import { useRouter } from "next/navigation"
import { usePathname, useRouter } from "next/navigation"
import type { CSSProperties, ReactNode } from "react"
import { useEffect } from "react"
@@ -16,13 +16,19 @@ export default function DashboardLayout({
children: ReactNode
}) {
const { ready, session } = useAuth()
const pathname = usePathname()
const router = useRouter()
const isLoginRoute = pathname?.startsWith("/dashboard/login") ?? false
useEffect(() => {
if (ready && !session) {
router.replace("/login")
if (ready && !session && !isLoginRoute) {
router.replace("/dashboard/login")
}
}, [ready, router, session])
}, [isLoginRoute, ready, router, session])
if (isLoginRoute) {
return <>{children}</>
}
if (!ready || !session) {
return (
@@ -1,5 +1,5 @@
import { LoginForm } from "@/components/login-form"
import { BotMessageSquareIcon, ShieldCheckIcon, UsersIcon, KeyRoundIcon } from "lucide-react"
import { BotMessageSquareIcon, ShieldCheckIcon } from "lucide-react"
import Link from "next/link"
import { Suspense } from "react"
@@ -47,7 +47,7 @@ export default function LoginPage() {
</div>
<div className="flex flex-col gap-4 p-6 md:p-10">
<div className="flex justify-center gap-2 md:justify-start">
<Link href="/login" className="flex items-center gap-2 font-medium">
<Link href="/dashboard/login" className="flex items-center gap-2 font-medium">
<div className="flex size-6 items-center justify-center rounded-md bg-primary text-primary-foreground">
<BotMessageSquareIcon className="size-4" />
</div>
@@ -31,7 +31,7 @@ function WxWorkLoginCallbackContent() {
if (!ticket) {
toast.error("企业微信登录票据不存在")
router.replace("/login")
router.replace("/dashboard/login")
return
}
@@ -42,7 +42,7 @@ function WxWorkLoginCallbackContent() {
})
.catch((error) => {
toast.error(error instanceof Error ? error.message : "企业微信登录失败")
router.replace("/login")
router.replace("/dashboard/login")
})
}, [router, searchParams])
Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 17 KiB

+1 -1
View File
@@ -15,7 +15,7 @@ export default function HomePage() {
<Link href="/dashboard">
</Link>
<Link href="/login">
<Link href="/dashboard/login">
</Link>
</div>