11import { initAuth } from "@/auth" ;
2- import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
3- import { SessionWithGeolocation } from "better-auth-cloudflare" ;
2+ import { Card , CardContent , CardFooter , CardHeader , CardTitle } from "@/components/ui/card" ;
43import { headers } from "next/headers" ;
4+ import Link from "next/link" ;
55import { redirect } from "next/navigation" ;
66import SignOutButton from "./SignOutButton" ; // Import the client component
77
@@ -14,8 +14,11 @@ export default async function DashboardPage() {
1414 redirect ( "/" ) ; // Redirect to home if no session
1515 }
1616
17- // Access Cloudflare data from session.session?.cloudflare or session.session?.geo
18- const cloudflareGeolocationData = session . session as SessionWithGeolocation ;
17+ // Get geolocation data from our plugin's endpoint
18+ const cloudflareGeolocationData = await authInstance . api . getGeolocation ( { headers : await headers ( ) } ) ;
19+
20+ // Access another plugin's endpoint to demonstrate plugin type inference is still intact
21+ const openAPISpec = await authInstance . api . generateOpenAPISchema ( ) ;
1922
2023 return (
2124 < div className = "flex flex-col items-center justify-center min-h-screen p-8 font-[family-name:var(--font-geist-sans)]" >
@@ -39,40 +42,50 @@ export default async function DashboardPage() {
3942 < strong > User ID:</ strong > { session . user . id }
4043 </ p >
4144 ) }
42- { cloudflareGeolocationData && (
45+ { cloudflareGeolocationData && "error" in cloudflareGeolocationData && (
46+ < p className = "text-md" >
47+ < strong > Error:</ strong > { cloudflareGeolocationData . error }
48+ </ p >
49+ ) }
50+ { cloudflareGeolocationData && ! ( "error" in cloudflareGeolocationData ) && (
4351 < >
4452 < p className = "text-md" >
45- < strong > Timezone:</ strong > { cloudflareGeolocationData . timezone }
53+ < strong > Timezone:</ strong > { cloudflareGeolocationData . timezone || "Unknown" }
4654 </ p >
4755 < p className = "text-md" >
48- < strong > City:</ strong > { cloudflareGeolocationData . city }
56+ < strong > City:</ strong > { cloudflareGeolocationData . city || "Unknown" }
4957 </ p >
5058 < p className = "text-md" >
51- < strong > Country:</ strong > { cloudflareGeolocationData . country }
59+ < strong > Country:</ strong > { cloudflareGeolocationData . country || "Unknown" }
5260 </ p >
5361 < p className = "text-md" >
54- < strong > Region:</ strong > { cloudflareGeolocationData . region }
62+ < strong > Region:</ strong > { cloudflareGeolocationData . region || "Unknown" }
5563 </ p >
5664 < p className = "text-md" >
57- < strong > Region Code:</ strong > { cloudflareGeolocationData . regionCode }
65+ < strong > Region Code:</ strong > { cloudflareGeolocationData . regionCode || "Unknown" }
5866 </ p >
5967 < p className = "text-md" >
60- < strong > Data Center:</ strong > { cloudflareGeolocationData . colo }
68+ < strong > Data Center:</ strong > { cloudflareGeolocationData . colo || "Unknown" }
6169 </ p >
6270 { cloudflareGeolocationData . latitude && (
6371 < p className = "text-md" >
64- < strong > Latitude:</ strong > { cloudflareGeolocationData . latitude }
72+ < strong > Latitude:</ strong > { cloudflareGeolocationData . latitude || "Unknown" }
6573 </ p >
6674 ) }
6775 { cloudflareGeolocationData . longitude && (
6876 < p className = "text-md" >
69- < strong > Longitude:</ strong > { cloudflareGeolocationData . longitude }
77+ < strong > Longitude:</ strong > { cloudflareGeolocationData . longitude || "Unknown" }
7078 </ p >
7179 ) }
7280 </ >
7381 ) }
7482 < SignOutButton /> { /* Use the client component for sign out */ }
7583 </ CardContent >
84+ < CardFooter >
85+ < Link href = "/api/auth/reference#tag/cloudflare/get/cloudflare/geolocation" className = "underline" >
86+ View OpenAPI v{ openAPISpec . openapi } Schema for Cloudflare Geolocation
87+ </ Link >
88+ </ CardFooter >
7689 </ Card >
7790 < footer className = "absolute bottom-0 w-full text-center text-sm text-gray-500 py-4" >
7891 Powered by{ " " }
0 commit comments