From 07d1dd6fc36c91f8b0a6afe5de0f93abcc944b73 Mon Sep 17 00:00:00 2001 From: Sean O'Connor Date: Wed, 14 Jan 2026 02:47:42 -0500 Subject: [PATCH] fix: remove proxy --- bun.lock | 4 +-- next.config.js | 1 + package.json | 2 +- src/app/auth/signin/page.tsx | 26 ++++++++++++---- src/lib/auth-client.ts | 58 ++---------------------------------- 5 files changed, 27 insertions(+), 64 deletions(-) diff --git a/bun.lock b/bun.lock index 9b5bdc2..614fd28 100644 --- a/bun.lock +++ b/bun.lock @@ -50,7 +50,7 @@ "framer-motion": "^12.23.26", "lucide-react": "^0.525.0", "next": "^16.1.1", - "pg": "^8.16.3", + "pg": "8.13.1", "react": "^19.2.3", "react-day-picker": "^9.12.0", "react-dom": "^19.2.3", @@ -1290,7 +1290,7 @@ "peberminta": ["peberminta@0.9.0", "", {}, "sha512-XIxfHpEuSJbITd1H3EeQwpcZbTLHc+VVr8ANI9t5sit565tsI4/xK3KWTUFE2e6QiangUkh3B0jihzmGnNrRsQ=="], - "pg": ["pg@8.16.3", "", { "dependencies": { "pg-connection-string": "^2.9.1", "pg-pool": "^3.10.1", "pg-protocol": "^1.10.3", "pg-types": "2.2.0", "pgpass": "1.0.5" }, "optionalDependencies": { "pg-cloudflare": "^1.2.7" }, "peerDependencies": { "pg-native": ">=3.0.1" }, "optionalPeers": ["pg-native"] }, "sha512-enxc1h0jA/aq5oSDMvqyW3q89ra6XIIDZgCX9vkMrnz5DFTw/Ny3Li2lFQ+pt3L6MCgm/5o2o8HW9hiJji+xvw=="], + "pg": ["pg@8.13.1", "", { "dependencies": { "pg-connection-string": "^2.7.0", "pg-pool": "^3.7.0", "pg-protocol": "^1.7.0", "pg-types": "^2.1.0", "pgpass": "1.x" }, "optionalDependencies": { "pg-cloudflare": "^1.1.1" }, "peerDependencies": { "pg-native": ">=3.0.1" }, "optionalPeers": ["pg-native"] }, "sha512-OUir1A0rPNZlX//c7ksiu7crsGZTKSOXJPgtNiHGIlC9H0lO+NC6ZDYksSgBYY/thSWhnSRBv8w1lieNNGATNQ=="], "pg-cloudflare": ["pg-cloudflare@1.2.7", "", {}, "sha512-YgCtzMH0ptvZJslLM1ffsY4EuGaU0cx4XSdXLRFae8bPP4dS5xL1tNB3k2o/N64cHJpwU7dxKli/nZ2lUa5fLg=="], diff --git a/next.config.js b/next.config.js index ee35ed5..b04cc87 100644 --- a/next.config.js +++ b/next.config.js @@ -6,6 +6,7 @@ import "./src/env.js"; /** @type {import("next").NextConfig} */ const config = { + serverExternalPackages: ['pg'], }; export default config; diff --git a/package.json b/package.json index 18e2fb3..7fc67ae 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "framer-motion": "^12.23.26", "lucide-react": "^0.525.0", "next": "^16.1.1", - "pg": "^8.16.3", + "pg": "8.13.1", "react": "^19.2.3", "react-day-picker": "^9.12.0", "react-dom": "^19.2.3", diff --git a/src/app/auth/signin/page.tsx b/src/app/auth/signin/page.tsx index 4d83f8e..8d5cc0e 100644 --- a/src/app/auth/signin/page.tsx +++ b/src/app/auth/signin/page.tsx @@ -49,12 +49,28 @@ function SignInForm() { } async function handleSocialSignIn() { + console.log("[SIGN IN PAGE] SSO button clicked"); + console.log("[SIGN IN PAGE] authClient:", authClient); + console.log("[SIGN IN PAGE] authClient.signIn:", authClient.signIn); + setLoading(true); - await authClient.signIn.sso({ - providerId: "authentik", - callbackURL: callbackUrl, - }); - setLoading(false); + try { + console.log("[SIGN IN PAGE] Calling authClient.signIn.sso with:", { + providerId: "authentik", + callbackURL: callbackUrl, + }); + + const result = await authClient.signIn.sso({ + providerId: "authentik", + callbackURL: callbackUrl, + }); + + console.log("[SIGN IN PAGE] SSO result:", result); + } catch (error) { + console.error("[SIGN IN PAGE] SSO error:", error); + } finally { + setLoading(false); + } } return ( diff --git a/src/lib/auth-client.ts b/src/lib/auth-client.ts index 0437e43..520e02e 100644 --- a/src/lib/auth-client.ts +++ b/src/lib/auth-client.ts @@ -6,64 +6,10 @@ import { ssoClient } from "@better-auth/sso/client"; /** * Auth client for better-auth with SSO support. * - * Uses a Proxy pattern to ensure the client is only created in the browser. - * This prevents SSR/build-time errors while maintaining full type safety. + * Better-auth handles SSR internally, so we can just create the client directly. */ -// Create a typed client reference for type inference -const _createClient = () => createAuthClient({ +export const authClient = createAuthClient({ baseURL: process.env.NEXT_PUBLIC_APP_URL, plugins: [ssoClient()], }); - -// Type for the full client including plugins -type AuthClientType = ReturnType; - -// Lazy initialization - only create the client when first accessed -let _client: AuthClientType | undefined; - -function getClient(): AuthClientType { - if (typeof window === "undefined") { - // During SSR, return a safe mock that won't crash - // The actual client will only be used in the browser - // @ts-ignore - SSR mock doesn't need full client implementation - return { - // @ts-ignore - useSession: () => ({ data: null, isPending: false, error: null }), - // @ts-ignore - signIn: { email: async () => { }, social: async () => { }, sso: async () => { } }, - // @ts-ignore - signOut: async () => { }, - // @ts-ignore - signUp: { email: async () => { } }, - }; - } - - if (!_client) { - _client = createAuthClient({ - baseURL: process.env.NEXT_PUBLIC_APP_URL, - plugins: [ssoClient()], - }); - } - - return _client; -} - -// Export a Proxy that lazy-loads the client -export const authClient = new Proxy({} as AuthClientType, { - get(_target, prop) { - // Always ensure we're in the browser before accessing the client - if (typeof window === "undefined") { - // During SSR, return safe defaults for common properties - if (prop === "useSession") { - return () => ({ data: null, isPending: false, error: null }); - } - return undefined; - } - - // In the browser, get the real client - const client = getClient(); - const value = client[prop as keyof AuthClientType]; - return typeof value === "function" ? value.bind(client) : value; - }, -});