From f06064fc810301bbc4b6a5f14f2645ec008b49ad Mon Sep 17 00:00:00 2001 From: kenneth Date: Sun, 14 Sep 2025 23:23:15 +0000 Subject: [PATCH] feat: log out and auth redirect --- src/dashboard/dashboard-sidebar.tsx | 41 +++++++++++++++++++---- src/routes/_authenticated.tsx | 52 +++++++++++++++++++++++++++-- src/routes/_authenticated/index.tsx | 4 +-- src/routes/login.tsx | 6 +++- 4 files changed, 90 insertions(+), 13 deletions(-) diff --git a/src/dashboard/dashboard-sidebar.tsx b/src/dashboard/dashboard-sidebar.tsx index cb15f47..0abd6f7 100644 --- a/src/dashboard/dashboard-sidebar.tsx +++ b/src/dashboard/dashboard-sidebar.tsx @@ -1,7 +1,17 @@ import { Link, useLocation } from "@tanstack/react-router" -import { FilesIcon, HomeIcon, User2Icon } from "lucide-react" +import { useAuth } from "@workos-inc/authkit-react" +import { + ChevronDownIcon, + FilesIcon, + HomeIcon, + LogOutIcon, + SettingsIcon, + User2Icon, +} from "lucide-react" import { DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" import { @@ -19,7 +29,7 @@ export function DashboardSidebar() { - + @@ -61,17 +71,34 @@ function MainSidebarMenu() { ) } -function UserSwitcher() { +function UserMenu() { + const { signOut } = useAuth() + + function handleSignOut() { + signOut() + } + return ( - -
- + +
+
- Kenneth + Kenneth +
+ + + + Settings + + + + Log out + + ) } diff --git a/src/routes/_authenticated.tsx b/src/routes/_authenticated.tsx index 7cb9654..f32e8d2 100644 --- a/src/routes/_authenticated.tsx +++ b/src/routes/_authenticated.tsx @@ -1,19 +1,65 @@ -import { createFileRoute, Navigate, Outlet } from "@tanstack/react-router" -import { Authenticated, Unauthenticated } from "convex/react" +import { + createFileRoute, + Navigate, + Outlet, + useLocation, +} from "@tanstack/react-router" +import { useAuth } from "@workos-inc/authkit-react" +import { + Authenticated, + AuthLoading, + Unauthenticated, + useConvexAuth, +} from "convex/react" +import { useEffect, useState } from "react" +import { LoadingSpinner } from "@/components/ui/loading-spinner" export const Route = createFileRoute("/_authenticated")({ component: AuthenticatedLayout, }) function AuthenticatedLayout() { + const { search } = useLocation() + const { isLoading } = useConvexAuth() + const { isLoading: authKitLoading } = useAuth() + const [hasProcessedAuth, setHasProcessedAuth] = useState(false) + + // Check if we're in the middle of processing an auth code + const hasAuthCode = search && typeof search === "object" && "code" in search + + // Track when auth processing is complete + useEffect(() => { + if (!authKitLoading && !isLoading) { + // Delay to ensure auth state is fully synchronized + const timer = setTimeout(() => { + setHasProcessedAuth(true) + }, 500) + return () => clearTimeout(timer) + } + }, [authKitLoading, isLoading]) + + // Show loading during auth code processing or while auth state is syncing + if (hasAuthCode || authKitLoading || isLoading || !hasProcessedAuth) { + return ( +
+ +
+ ) + } + return ( <> - + + +
+ +
+
) } diff --git a/src/routes/_authenticated/index.tsx b/src/routes/_authenticated/index.tsx index 7397147..e2f8f1f 100644 --- a/src/routes/_authenticated/index.tsx +++ b/src/routes/_authenticated/index.tsx @@ -1,9 +1,9 @@ -import { createFileRoute } from "@tanstack/react-router" +import { createFileRoute, Navigate } from "@tanstack/react-router" export const Route = createFileRoute("/_authenticated")({ component: RouteComponent, }) function RouteComponent() { - return
Hello "/"!
+ return } diff --git a/src/routes/login.tsx b/src/routes/login.tsx index 4ac8880..feb8647 100644 --- a/src/routes/login.tsx +++ b/src/routes/login.tsx @@ -1,9 +1,13 @@ import { createFileRoute } from "@tanstack/react-router" +import { useAuth } from "@workos-inc/authkit-react" +import { Button } from "../components/ui/button" export const Route = createFileRoute("/login")({ component: RouteComponent, }) function RouteComponent() { - return
Hello "/login"!
+ const { signIn } = useAuth() + + return }