Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/integrations/github/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
ShieldCheck,
Users,
} from "lucide-react"
import { getSession } from "@/lib/session"
import { getOptionalSession, isSessionConfigured } from "@/lib/session"
import {
getGitHubAppInstallation,
isGitHubAppConfigured,
Expand All @@ -35,9 +35,9 @@ export default async function GitHubIntegrationPage({
searchParams: Promise<Record<string, string | string[] | undefined>>
}) {
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<ReturnType<typeof getGitHubAppInstallation>> | null = null
let repositories: Awaited<ReturnType<typeof listInstallationRepositories>> = []
Expand Down
23 changes: 14 additions & 9 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Link from "next/link"
import { getSession } from "@/lib/session"
import { getOptionalSession, isSessionConfigured } from "@/lib/session"
import {
Activity,
BarChart3,
Expand All @@ -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 (
<div className="min-h-screen bg-background text-foreground flex flex-col">
Expand Down Expand Up @@ -106,12 +109,14 @@ export default async function HomePage() {

<UsernameForm className="flex flex-col items-center" />

<Link
href={signedIn ? "/dashboard" : "/api/auth"}
className="text-xs text-muted-foreground underline-offset-4 hover:text-foreground hover:underline"
>
{signedIn ? "Open legacy hosted dashboard" : "Legacy hosted sign-in"}
</Link>
{(signedIn || hostedAuthAvailable) && (
<Link
href={signedIn ? "/dashboard" : "/api/auth"}
className="text-xs text-muted-foreground underline-offset-4 hover:text-foreground hover:underline"
>
{signedIn ? "Open legacy hosted dashboard" : "Legacy hosted sign-in"}
</Link>
)}
</div>
</div>

Expand Down
6 changes: 3 additions & 3 deletions app/u/[username]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }>
Expand Down Expand Up @@ -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 (
<div className="min-h-screen bg-background">
Expand Down
10 changes: 10 additions & 0 deletions lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,3 +62,8 @@ export async function getSession() {
getSessionOptions()
)
}

export async function getOptionalSession() {
if (!isSessionConfigured()) return null
return getSession()
}
Loading