diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index 2fc19b0..c77f482 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import type { LucideIcon } from "lucide-react"; import { Bell, @@ -14,7 +14,7 @@ import { Sun, X } from "lucide-react"; -import { Navigate, Route, Routes, useNavigate } from "react-router-dom"; +import { Navigate, Route, Routes, useLocation, useNavigate } from "react-router-dom"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; import { EmailLoginPage } from "@/pages/email-login-page"; @@ -66,6 +66,10 @@ function App() { const [sidebarCollapsed, setSidebarCollapsed] = useState(false); const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false); const navigate = useNavigate(); + const location = useLocation(); + + const isAuthPage = + location.pathname === "/login/email" || location.pathname.startsWith("/auth/callback/"); useEffect(() => { applyThemeMode(themeMode); @@ -95,6 +99,19 @@ function App() { setThemeMode((currentTheme) => (currentTheme === "dark" ? "light" : "dark")); } + function handleLoginSuccess(payload: EmailLoginResult): void { + const nextSession = toWebSession(payload); + saveSession(nextSession); + setSession(nextSession); + setMobileSidebarOpen(false); + navigate("/", { replace: true }); + } + + function handleBootstrapSession(nextSession: WebSession): void { + setSession(nextSession); + setMobileSidebarOpen(false); + } + function renderSidebarContent(options: { collapsed: boolean; mobile: boolean }) { const { collapsed, mobile } = options; @@ -124,9 +141,8 @@ function App() { key={item.key} type="button" className={cn( - "group flex w-full items-center rounded-xl border border-transparent text-left transition-colors", - "hover:border-primary/25 hover:bg-primary/10", - "gap-3 px-3 py-2.5" + "group flex w-full items-center rounded-xl border border-transparent px-3 py-2.5 text-left transition-colors", + "gap-3 hover:border-primary/25 hover:bg-primary/10" )} > @@ -150,10 +166,7 @@ function App() { {themeMode === "dark" ? : } @@ -167,10 +180,7 @@ function App() { @@ -184,6 +194,28 @@ function App() { ); } + if (isAuthPage) { + return ( + + + + + } + /> + } + /> + } /> + + + + + ); + } + return ( @@ -202,11 +234,7 @@ function App() { alt="TodoList" className="h-9 w-9 shrink-0 rounded-xl shadow-sm" /> - - - TodoList - - + TodoList {session ? session.user.email : "未登录"} @@ -232,7 +260,7 @@ function App() { {renderSidebarContent({ collapsed: false, mobile: true })} - +