feat(auth): update login routes and add WxWork login callback handling
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { Loader2Icon } from "lucide-react"
|
import { Loader2Icon } from "lucide-react"
|
||||||
import { useRouter } from "next/navigation"
|
import { usePathname, useRouter } from "next/navigation"
|
||||||
import type { CSSProperties, ReactNode } from "react"
|
import type { CSSProperties, ReactNode } from "react"
|
||||||
import { useEffect } from "react"
|
import { useEffect } from "react"
|
||||||
|
|
||||||
@@ -16,13 +16,19 @@ export default function DashboardLayout({
|
|||||||
children: ReactNode
|
children: ReactNode
|
||||||
}) {
|
}) {
|
||||||
const { ready, session } = useAuth()
|
const { ready, session } = useAuth()
|
||||||
|
const pathname = usePathname()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
const isLoginRoute = pathname?.startsWith("/dashboard/login") ?? false
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ready && !session) {
|
if (ready && !session && !isLoginRoute) {
|
||||||
router.replace("/login")
|
router.replace("/dashboard/login")
|
||||||
}
|
}
|
||||||
}, [ready, router, session])
|
}, [isLoginRoute, ready, router, session])
|
||||||
|
|
||||||
|
if (isLoginRoute) {
|
||||||
|
return <>{children}</>
|
||||||
|
}
|
||||||
|
|
||||||
if (!ready || !session) {
|
if (!ready || !session) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { LoginForm } from "@/components/login-form"
|
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 Link from "next/link"
|
||||||
import { Suspense } from "react"
|
import { Suspense } from "react"
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ export default function LoginPage() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-4 p-6 md:p-10">
|
<div className="flex flex-col gap-4 p-6 md:p-10">
|
||||||
<div className="flex justify-center gap-2 md:justify-start">
|
<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">
|
<div className="flex size-6 items-center justify-center rounded-md bg-primary text-primary-foreground">
|
||||||
<BotMessageSquareIcon className="size-4" />
|
<BotMessageSquareIcon className="size-4" />
|
||||||
</div>
|
</div>
|
||||||
+2
-2
@@ -31,7 +31,7 @@ function WxWorkLoginCallbackContent() {
|
|||||||
|
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
toast.error("企业微信登录票据不存在")
|
toast.error("企业微信登录票据不存在")
|
||||||
router.replace("/login")
|
router.replace("/dashboard/login")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ function WxWorkLoginCallbackContent() {
|
|||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
toast.error(error instanceof Error ? error.message : "企业微信登录失败")
|
toast.error(error instanceof Error ? error.message : "企业微信登录失败")
|
||||||
router.replace("/login")
|
router.replace("/dashboard/login")
|
||||||
})
|
})
|
||||||
}, [router, searchParams])
|
}, [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 href="/dashboard">
|
||||||
进入控制台
|
进入控制台
|
||||||
</Link>
|
</Link>
|
||||||
<Link href="/login">
|
<Link href="/dashboard/login">
|
||||||
登录后台
|
登录后台
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const [session, setSession] = useState<AuthSession | null>(null)
|
const [session, setSession] = useState<AuthSession | null>(null)
|
||||||
const [ready, setReady] = useState(false)
|
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 refreshProfile = useCallback(async () => {
|
||||||
const stored = readSession()
|
const stored = readSession()
|
||||||
@@ -58,7 +59,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
setSession(null)
|
setSession(null)
|
||||||
if (requiresAuth) {
|
if (requiresAuth) {
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
router.replace("/login")
|
router.replace("/dashboard/login")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -71,7 +72,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
await logout(current?.refreshToken)
|
await logout(current?.refreshToken)
|
||||||
setSession(null)
|
setSession(null)
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
router.replace("/login")
|
router.replace("/dashboard/login")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
setReady(true)
|
setReady(true)
|
||||||
if (requiresAuth) {
|
if (requiresAuth) {
|
||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
router.replace("/login")
|
router.replace("/dashboard/login")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}, [requiresAuth, refreshProfile, router])
|
}, [requiresAuth, refreshProfile, router])
|
||||||
|
|||||||
+1
-1
Submodule docs updated: 688d3b0618...2c062610c4
@@ -75,7 +75,7 @@ func (c *AuthController) GetWxwork_callback() {
|
|||||||
c.redirectWxWorkError(err.Error())
|
c.redirectWxWorkError(err.Error())
|
||||||
return
|
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 {
|
func (c *AuthController) PostWxwork_exchange() *web.JsonResult {
|
||||||
|
|||||||
Reference in New Issue
Block a user