-
-
Notifications
You must be signed in to change notification settings - Fork 6
Fix Unauthorized error and implement ENABLE_AUTH logic #515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: sync/main-auth-backend-final-13145176703902541894
Are you sure you want to change the base?
Changes from all commits
960ea89
9db9100
d1f25a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| AUTH_DISABLED_FOR_DEV=false | ||
| DATABASE_URL="postgresql://user:password@host:port/db" | ||
| DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres | ||
| SERVER_ACTIONS_ALLOWED_ORIGINS=* | ||
| STANDARD_TIER_BILLING_CYCLE="yearly" | ||
| STANDARD_TIER_CREDITS=500 | ||
| STANDARD_TIER_MONTHLY_PRICE=500 | ||
| STANDARD_TIER_PRICE_ID="price_standard_500_yearly" | ||
| ENABLE_SHARE=true | ||
| ENABLE_AUTH=true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| "use client" | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| import Image from "next/image" | ||
| import { AuthPage } from "@/components/auth" | ||
| import { useAuth } from "@/lib/auth/v0" | ||
|
|
||
| function Logo() { | ||
| return ( | ||
| <div className="flex items-center gap-2 text-xl font-semibold"> | ||
| <Image src="/images/logo-green.png" alt="QCX Logo" width={32} height={32} /> | ||
| QCX | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| function ArtPanel() { | ||
| return ( | ||
| <div className="relative flex h-full w-full items-center justify-center overflow-hidden rounded-3xl"> | ||
| <Image src="/images/abstract-art.png" alt="Abstract art" fill className="object-cover" priority /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export function AuthClientPage() { | ||
| const { | ||
| isLoading, | ||
| error, | ||
| magicLinkSent, | ||
| magicLinkEmail, | ||
| handleGoogleSignIn, | ||
| handleMagicLink, | ||
| resetError, | ||
| resetMagicLink, | ||
| } = useAuth({ | ||
| // Optional callbacks for additional handling | ||
| onMagicLinkSent: (email) => { | ||
| console.log("Magic link sent to:", email) | ||
| }, | ||
| onError: (error) => { | ||
| console.error("Auth error:", error) | ||
| }, | ||
| }) | ||
|
|
||
| return ( | ||
| <AuthPage | ||
| title="Welcome to QCX" | ||
| subtitle="Let's get you started with Quality Computer Experiences" | ||
| logo={<Logo />} | ||
| onGoogleSignIn={handleGoogleSignIn} | ||
| onMagicLinkSubmit={handleMagicLink} | ||
| showGitHub={false} | ||
| decorativePanel={<ArtPanel />} | ||
| isLoading={isLoading} | ||
| error={error} | ||
| magicLinkSent={magicLinkSent} | ||
| magicLinkEmail={magicLinkEmail} | ||
| onResetMagicLink={resetMagicLink} | ||
| onResetError={resetError} | ||
| /> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,63 +1,17 @@ | ||
| "use client" | ||
| import { getCurrentUserIdOnServer } from "@/lib/auth/get-current-user" | ||
| import { redirect } from "next/navigation" | ||
| import { AuthClientPage } from "./auth-client-page" | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| import Image from "next/image" | ||
| import { AuthPage } from "@/components/auth" | ||
| import { useAuth } from "@/lib/auth/v0" | ||
| export default async function LoginPage() { | ||
| const userId = await getCurrentUserIdOnServer() | ||
| const isAuthEnabled = process.env.ENABLE_AUTH === 'true' | ||
|
|
||
| function Logo() { | ||
| return ( | ||
| <div className="flex items-center gap-2 text-xl font-semibold"> | ||
| <Image src="/images/logo-green.png" alt="QCX Logo" width={32} height={32} /> | ||
| QCX | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| function ArtPanel() { | ||
| return ( | ||
| <div className="relative flex h-full w-full items-center justify-center overflow-hidden rounded-3xl"> | ||
| <Image src="/images/abstract-art.png" alt="Abstract art" fill className="object-cover" priority /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default function LoginPage() { | ||
| const { | ||
| isLoading, | ||
| error, | ||
| magicLinkSent, | ||
| magicLinkEmail, | ||
| handleGoogleSignIn, | ||
| handleMagicLink, | ||
| resetError, | ||
| resetMagicLink, | ||
| } = useAuth({ | ||
| // Optional callbacks for additional handling | ||
| onMagicLinkSent: (email) => { | ||
| console.log("Magic link sent to:", email) | ||
| }, | ||
| onError: (error) => { | ||
| console.error("Auth error:", error) | ||
| }, | ||
| }) | ||
| // If auth is disabled, redirect to home as we are always "logged in" as anonymous user | ||
| if (!isAuthEnabled && userId) { | ||
| redirect('/') | ||
| } | ||
|
|
||
| return ( | ||
| <AuthPage | ||
| title="Welcome to QCX" | ||
| subtitle="Let's get you started with Quality Computer Experiences" | ||
| logo={<Logo />} | ||
| onGoogleSignIn={handleGoogleSignIn} | ||
| onMagicLinkSubmit={handleMagicLink} | ||
| showGitHub={false} | ||
| decorativePanel={<ArtPanel />} | ||
| isLoading={isLoading} | ||
| error={error} | ||
| magicLinkSent={magicLinkSent} | ||
| magicLinkEmail={magicLinkEmail} | ||
| onResetMagicLink={resetMagicLink} | ||
| onResetError={resetError} | ||
| /> | ||
| ) | ||
| return <AuthClientPage /> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,27 @@ | ||
| import { Chat } from '@/components/chat' | ||
| import { nanoid } from '@/lib/utils' | ||
| import { AI } from './actions' | ||
| import { getCurrentUserIdOnServer } from '@/lib/auth/get-current-user' | ||
| import { getSupabaseUserAndSessionOnServer } from '@/lib/auth/get-current-user' | ||
| import { redirect } from 'next/navigation' | ||
| import { MapDataProvider } from '@/components/map/map-data-context' | ||
| import { ensureUserExists } from '@/lib/actions/users' | ||
|
|
||
| export const maxDuration = 60 | ||
| export const dynamic = 'force-dynamic' | ||
|
|
||
| export default async function Page() { | ||
| const userId = await getCurrentUserIdOnServer() | ||
| const { user } = await getSupabaseUserAndSessionOnServer() | ||
| const guestChatEnabled = process.env.ENABLE_GUEST_CHAT === 'true' | ||
|
|
||
| if (!userId) { | ||
| if (!user && !guestChatEnabled) { | ||
| redirect('/auth') | ||
| } | ||
|
|
||
| // Ensure user exists in public.users table if they are authenticated | ||
| if (user) { | ||
| await ensureUserExists(user.id, user.email) | ||
| } | ||
|
|
||
|
Comment on lines
11
to
24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That can create an infinite loop or confusing UX: SuggestionConsider handling the "auth enabled but misconfigured" case explicitly. For example:
Reply with "@CharlieHelps yes please" if you'd like me to add a commit that threads |
||
| const id = nanoid() | ||
| return ( | ||
| <AI initialAIState={{ chatId: id, messages: [] }}> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Client component logs auth events (
console.log/console.error) for magic link and errors. In production, this can leak PII (email) into client logs and create noisy telemetry.Since these callbacks are "optional" and not used for UX, it's better to remove them or gate them behind a dev check.
Suggestion
Remove these callbacks or gate them:
Reply with "@CharlieHelps yes please" if you'd like me to add a commit that removes/gates these logs.