Author SHA1 Message Date
Leon SerfatyandClaude Opus 4.8 595a5e3e04 feat(auth): hide Google sign-in until OAuth is configured
Google social login has no credentials in production, so the "Continue with
Google" button (and its divider) errored on click. Gate the button + divider on
a new isGoogleConfigured() helper (requires GOOGLE_CLIENT_ID + GOOGLE_CLIENT_SECRET)
on both the login and signup pages, and guard the signInWithGoogle action as
defense in depth. The button reappears automatically once both env vars are set.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 08:26:08 -04:00
Leon SerfatyandClaude Opus 4.8 e5e987eb4c fix(csp): whitelist Umami analytics origin so tracking works
The CSP script-src/connect-src didn't include the Umami host
(fickanalytics.phluit.net), so the browser blocked both loading script.js and
the event beacons (POST /api/send) — analytics recorded 0 visits despite the
site being live. Add a umamiOrigin() helper (derived from NEXT_PUBLIC_UMAMI_SRC,
defaulting to the shared phluit instance) and include it in script-src and
connect-src.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-03 07:37:35 -04:00
5 changed files with 84 additions and 40 deletions
+23 -18
View File
@@ -3,6 +3,7 @@ import Link from "next/link"
import { Logo } from "@/components/shared/logo" import { Logo } from "@/components/shared/logo"
import { TurnstileWidget } from "@/components/shared/turnstile-widget" import { TurnstileWidget } from "@/components/shared/turnstile-widget"
import { signIn, signInWithGoogle } from "@/app/actions/auth" import { signIn, signInWithGoogle } from "@/app/actions/auth"
import { isGoogleConfigured } from "@/lib/auth"
export const metadata: Metadata = { export const metadata: Metadata = {
title: "Sign in", title: "Sign in",
@@ -28,25 +29,29 @@ export default async function LoginPage({
</div> </div>
<div className="rounded-xl border border-white/10 bg-[#111118] p-8"> <div className="rounded-xl border border-white/10 bg-[#111118] p-8">
{/* Google OAuth */} {isGoogleConfigured() && (
<form action={signInWithGoogle}> <>
<button {/* Google OAuth */}
type="submit" <form action={signInWithGoogle}>
className="flex w-full items-center justify-center gap-3 rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-white/10" <button
> type="submit"
<GoogleIcon /> className="flex w-full items-center justify-center gap-3 rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-white/10"
Continue with Google >
</button> <GoogleIcon />
</form> Continue with Google
</button>
</form>
<div className="relative my-6"> <div className="relative my-6">
<div className="absolute inset-0 flex items-center"> <div className="absolute inset-0 flex items-center">
<div className="w-full border-t border-white/10" /> <div className="w-full border-t border-white/10" />
</div> </div>
<div className="relative flex justify-center text-xs"> <div className="relative flex justify-center text-xs">
<span className="bg-[#111118] px-3 text-white/40">or continue with email</span> <span className="bg-[#111118] px-3 text-white/40">or continue with email</span>
</div> </div>
</div> </div>
</>
)}
{/* Error / Success messages */} {/* Error / Success messages */}
{error && ( {error && (
+23 -18
View File
@@ -2,6 +2,7 @@ import Link from "next/link"
import { Logo } from "@/components/shared/logo" import { Logo } from "@/components/shared/logo"
import { TurnstileWidget } from "@/components/shared/turnstile-widget" import { TurnstileWidget } from "@/components/shared/turnstile-widget"
import { signUp, signInWithGoogle } from "@/app/actions/auth" import { signUp, signInWithGoogle } from "@/app/actions/auth"
import { isGoogleConfigured } from "@/lib/auth"
export default async function SignupPage({ export default async function SignupPage({
searchParams, searchParams,
@@ -47,25 +48,29 @@ export default async function SignupPage({
</div> </div>
<div className="rounded-xl border border-white/10 bg-[#111118] p-8"> <div className="rounded-xl border border-white/10 bg-[#111118] p-8">
{/* Google OAuth */} {isGoogleConfigured() && (
<form action={signInWithGoogle}> <>
<button {/* Google OAuth */}
type="submit" <form action={signInWithGoogle}>
className="flex w-full items-center justify-center gap-3 rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-white/10" <button
> type="submit"
<GoogleIcon /> className="flex w-full items-center justify-center gap-3 rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-sm font-medium text-white transition hover:bg-white/10"
Continue with Google >
</button> <GoogleIcon />
</form> Continue with Google
</button>
</form>
<div className="relative my-6"> <div className="relative my-6">
<div className="absolute inset-0 flex items-center"> <div className="absolute inset-0 flex items-center">
<div className="w-full border-t border-white/10" /> <div className="w-full border-t border-white/10" />
</div> </div>
<div className="relative flex justify-center text-xs"> <div className="relative flex justify-center text-xs">
<span className="bg-[#111118] px-3 text-white/40">or sign up with email</span> <span className="bg-[#111118] px-3 text-white/40">or sign up with email</span>
</div> </div>
</div> </div>
</>
)}
{error && ( {error && (
<div className="mb-4 rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-400"> <div className="mb-4 rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-400">
+6 -1
View File
@@ -3,7 +3,7 @@
import { redirect } from "next/navigation" import { redirect } from "next/navigation"
import { headers } from "next/headers" import { headers } from "next/headers"
import { APIError } from "better-auth/api" import { APIError } from "better-auth/api"
import { auth } from "@/lib/auth" import { auth, isGoogleConfigured } from "@/lib/auth"
import { verifyTurnstile } from "@/lib/turnstile" import { verifyTurnstile } from "@/lib/turnstile"
const APP_URL = process.env.NEXT_PUBLIC_APP_URL ?? "http://localhost:3000" const APP_URL = process.env.NEXT_PUBLIC_APP_URL ?? "http://localhost:3000"
@@ -77,6 +77,11 @@ export async function signIn(formData: FormData) {
} }
export async function signInWithGoogle() { export async function signInWithGoogle() {
// Defense in depth: the auth pages hide the Google button when it isn't
// configured, but guard the action too in case it's POSTed directly.
if (!isGoogleConfigured()) {
redirect(`/login?error=${encodeURIComponent("Google sign-in isn't available right now.")}`)
}
let url: string | undefined let url: string | undefined
try { try {
const res = await auth.api.signInSocial({ const res = await auth.api.signInSocial({
+9
View File
@@ -116,3 +116,12 @@ export const auth = betterAuth({
], ],
}) })
/**
* Whether Google OAuth is configured. The auth pages hide the "Continue with
* Google" button unless BOTH credentials are present, so users never see a
* social option that can't complete. Mirrors socialProviders.google above.
*/
export function isGoogleConfigured(): boolean {
return Boolean(process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET)
}
+23 -3
View File
@@ -41,6 +41,19 @@ function sentryIngestOrigin(): string | null {
} }
} }
// Origin serving the Umami analytics script (script.js) and receiving its event
// beacons (POST /api/send). Mirrors the component default so the CSP allows both
// loading the script AND sending events; stays in sync with NEXT_PUBLIC_UMAMI_SRC
// when overridden.
function umamiOrigin(): string {
const src = process.env.NEXT_PUBLIC_UMAMI_SRC || "https://fickanalytics.phluit.net/script.js"
try {
return new URL(src).origin
} catch {
return ""
}
}
// Build the Content-Security-Policy. `script-src` uses 'unsafe-inline' because // Build the Content-Security-Policy. `script-src` uses 'unsafe-inline' because
// Next.js 16's Turbopack build does NOT stamp a per-request nonce onto its // Next.js 16's Turbopack build does NOT stamp a per-request nonce onto its
// inline hydration scripts (`self.__next_f.push(...)`). A nonce-based policy // inline hydration scripts (`self.__next_f.push(...)`). A nonce-based policy
@@ -54,13 +67,20 @@ function buildCsp(): string {
// Dev additionally needs 'unsafe-eval' (Turbopack HMR) plus a dev websocket // Dev additionally needs 'unsafe-eval' (Turbopack HMR) plus a dev websocket
// (added to connect-src below). // (added to connect-src below).
const scriptSrc = isDev const umami = umamiOrigin()
? `script-src 'self' 'unsafe-inline' 'unsafe-eval' https://challenges.cloudflare.com` const scriptSrc = [
: `script-src 'self' 'unsafe-inline' https://challenges.cloudflare.com` "script-src 'self' 'unsafe-inline'",
isDev ? "'unsafe-eval'" : "",
"https://challenges.cloudflare.com",
umami, // load the Umami analytics script
]
.filter(Boolean)
.join(" ")
const connectSrc = [ const connectSrc = [
"connect-src 'self'", "connect-src 'self'",
isDev ? "ws: wss:" : "", isDev ? "ws: wss:" : "",
"https://api.stripe.com https://api.openai.com https://challenges.cloudflare.com", "https://api.stripe.com https://api.openai.com https://challenges.cloudflare.com",
umami, // Umami event beacons (POST /api/send)
sentry ?? "", sentry ?? "",
] ]
.filter(Boolean) .filter(Boolean)