diff --git a/src/app/api/auth/session/route.ts b/src/app/api/auth/session/route.ts index 5b72013..8e8eed4 100644 --- a/src/app/api/auth/session/route.ts +++ b/src/app/api/auth/session/route.ts @@ -1,31 +1,27 @@ import { NextResponse } from "next/server"; - -// Mock session data for demo purposes -// In a real app, this would check the actual Better Auth session -const mockSession = { - user: { - id: "demo-user-123", - name: "Demo User", - email: "demo@example.com", - emailVerified: true, - image: "https://via.placeholder.com/40" - }, - expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString() -}; +import { auth } from "@/lib/auth"; export async function GET(request: Request) { try { - // For demo purposes, we'll always return an authenticated user - // This simulates a successful OAuth login scenario - - // In a real implementation, you would: - // 1. Check for valid session cookies/tokens - // 2. Validate the session with Better Auth - // 3. Return the actual user data - + // Use Better Auth to get the actual session + const session = await auth.api.getSession({ + headers: request.headers, + }); + + if (session?.user) { + return NextResponse.json({ + session: { + user: session.user, + expires: session.session?.expiresAt + }, + user: session.user + }); + } + + // If no session found, return not authenticated return NextResponse.json({ - session: mockSession, - user: mockSession.user + session: null, + user: null }); } catch (error) { console.error("Session check error:", error); diff --git a/src/components/auth/user-profile.tsx b/src/components/auth/user-profile.tsx index 00556d0..8b09b0d 100644 --- a/src/components/auth/user-profile.tsx +++ b/src/components/auth/user-profile.tsx @@ -1,7 +1,7 @@ "use client"; -import { useSession, signOut } from "@/lib/auth-client"; -import { SignInButton } from "./sign-in-button"; +import { useAuth } from "@/hooks/use-auth"; +import { Button } from "@/components/ui/button"; import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar"; import { DropdownMenu, @@ -12,29 +12,25 @@ import { DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import Link from "next/link"; -import { useRouter } from "next/navigation"; import { User, LogOut } from "lucide-react"; export function UserProfile() { - const { data: session, isPending } = useSession(); - const router = useRouter(); + const { user, isAuthenticated, isLoading, login, logout } = useAuth(); - if (isPending) { + if (isLoading) { return
- {session.user?.name} + {user?.name}
- {session.user?.email} + {user?.email}