feat(auth): update login routes and add WxWork login callback handling
This commit is contained in:
@@ -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>
|
||||
+2
-2
@@ -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 |
@@ -15,7 +15,7 @@ export default function HomePage() {
|
||||
<Link href="/dashboard">
|
||||
进入控制台
|
||||
</Link>
|
||||
<Link href="/login">
|
||||
<Link href="/dashboard/login">
|
||||
登录后台
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
@@ -33,7 +33,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const router = useRouter()
|
||||
const [session, setSession] = useState<AuthSession | null>(null)
|
||||
const [ready, setReady] = useState(false)
|
||||
const requiresAuth = pathname?.startsWith("/dashboard") ?? false
|
||||
const isDashboardLoginRoute = pathname?.startsWith("/dashboard/login") ?? false
|
||||
const requiresAuth = (pathname?.startsWith("/dashboard") ?? false) && !isDashboardLoginRoute
|
||||
|
||||
const refreshProfile = useCallback(async () => {
|
||||
const stored = readSession()
|
||||
@@ -58,7 +59,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
setSession(null)
|
||||
if (requiresAuth) {
|
||||
startTransition(() => {
|
||||
router.replace("/login")
|
||||
router.replace("/dashboard/login")
|
||||
})
|
||||
}
|
||||
} finally {
|
||||
@@ -71,7 +72,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
await logout(current?.refreshToken)
|
||||
setSession(null)
|
||||
startTransition(() => {
|
||||
router.replace("/login")
|
||||
router.replace("/dashboard/login")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
setReady(true)
|
||||
if (requiresAuth) {
|
||||
startTransition(() => {
|
||||
router.replace("/login")
|
||||
router.replace("/dashboard/login")
|
||||
})
|
||||
}
|
||||
}, [requiresAuth, refreshProfile, router])
|
||||
|
||||
+1
-1
Submodule docs updated: 688d3b0618...2c062610c4
@@ -75,7 +75,7 @@ func (c *AuthController) GetWxwork_callback() {
|
||||
c.redirectWxWorkError(err.Error())
|
||||
return
|
||||
}
|
||||
c.Ctx.Redirect("/login/wxwork/callback?ticket="+url.QueryEscape(ticket)+"&next="+url.QueryEscape(next), iris.StatusFound)
|
||||
c.Ctx.Redirect("/dashboard/login/wxwork/callback?ticket="+url.QueryEscape(ticket)+"&next="+url.QueryEscape(next), iris.StatusFound)
|
||||
}
|
||||
|
||||
func (c *AuthController) PostWxwork_exchange() *web.JsonResult {
|
||||
|
||||
Reference in New Issue
Block a user