diff --git a/app/integrations/github/page.tsx b/app/integrations/github/page.tsx index cb97eb0..15bbb2b 100644 --- a/app/integrations/github/page.tsx +++ b/app/integrations/github/page.tsx @@ -11,7 +11,7 @@ import { ShieldCheck, Users, } from "lucide-react" -import { getSession } from "@/lib/session" +import { getOptionalSession, isSessionConfigured } from "@/lib/session" import { getGitHubAppInstallation, isGitHubAppConfigured, @@ -35,9 +35,9 @@ export default async function GitHubIntegrationPage({ searchParams: Promise> }) { const params = await searchParams - const session = await getSession() - const configured = isGitHubAppConfigured() - const linked = session.githubAppInstallation + const session = await getOptionalSession() + const configured = isGitHubAppConfigured() && isSessionConfigured() + const linked = session?.githubAppInstallation let installation: Awaited> | null = null let repositories: Awaited> = [] diff --git a/app/page.tsx b/app/page.tsx index 2ddc2f9..1360465 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,5 +1,5 @@ import Link from "next/link" -import { getSession } from "@/lib/session" +import { getOptionalSession, isSessionConfigured } from "@/lib/session" import { Activity, BarChart3, @@ -16,8 +16,11 @@ import { ThemeToggle } from "@/components/theme-toggle" import { UsernameForm } from "@/components/username-form" export default async function HomePage() { - const session = await getSession() - const signedIn = Boolean(session.user && session.accessToken) + const session = await getOptionalSession() + const signedIn = Boolean(session?.user && session?.accessToken) + const hostedAuthAvailable = + isSessionConfigured() && + Boolean(process.env.GITHUB_CLIENT_ID && process.env.GITHUB_CLIENT_SECRET) return (
@@ -106,12 +109,14 @@ export default async function HomePage() { - - {signedIn ? "Open legacy hosted dashboard" : "Legacy hosted sign-in"} - + {(signedIn || hostedAuthAvailable) && ( + + {signedIn ? "Open legacy hosted dashboard" : "Legacy hosted sign-in"} + + )}
diff --git a/app/u/[username]/page.tsx b/app/u/[username]/page.tsx index d5a4b4d..fbe1890 100644 --- a/app/u/[username]/page.tsx +++ b/app/u/[username]/page.tsx @@ -7,7 +7,7 @@ import { GitHubLogoIcon } from "@radix-ui/react-icons" import { DashboardClient } from "@/components/dashboard-client" import { ThemeToggle } from "@/components/theme-toggle" import { fetchProfile, GitHubError, type PublicProfile } from "@/lib/github" -import { getSession } from "@/lib/session" +import { getOptionalSession } from "@/lib/session" interface Props { params: Promise<{ username: string }> @@ -39,8 +39,8 @@ export default async function PublicReportPage({ params }: Props) { const profile = await loadProfile(username) if (!profile) notFound() - const session = await getSession() - const isOwner = session.user?.login.toLowerCase() === profile.login.toLowerCase() + const session = await getOptionalSession() + const isOwner = session?.user?.login.toLowerCase() === profile.login.toLowerCase() return (
diff --git a/lib/session.ts b/lib/session.ts index 9e0b827..234526c 100644 --- a/lib/session.ts +++ b/lib/session.ts @@ -27,6 +27,11 @@ export interface SessionData { githubAppOAuthState?: string } +export function isSessionConfigured() { + const configured = process.env.SESSION_SECRET + return process.env.NODE_ENV !== "production" || Boolean(configured && configured.length >= 32) +} + function getSessionPassword() { const configured = process.env.SESSION_SECRET if (configured && configured.length >= 32) return configured @@ -57,3 +62,8 @@ export async function getSession() { getSessionOptions() ) } + +export async function getOptionalSession() { + if (!isSessionConfigured()) return null + return getSession() +}