fix: remove proxy

This commit is contained in:
2026-01-14 02:47:42 -05:00
parent d5f337df80
commit 07d1dd6fc3
5 changed files with 27 additions and 64 deletions

View File

@@ -50,7 +50,7 @@
"framer-motion": "^12.23.26", "framer-motion": "^12.23.26",
"lucide-react": "^0.525.0", "lucide-react": "^0.525.0",
"next": "^16.1.1", "next": "^16.1.1",
"pg": "^8.16.3", "pg": "8.13.1",
"react": "^19.2.3", "react": "^19.2.3",
"react-day-picker": "^9.12.0", "react-day-picker": "^9.12.0",
"react-dom": "^19.2.3", "react-dom": "^19.2.3",
@@ -1290,7 +1290,7 @@
"peberminta": ["peberminta@0.9.0", "", {}, "sha512-XIxfHpEuSJbITd1H3EeQwpcZbTLHc+VVr8ANI9t5sit565tsI4/xK3KWTUFE2e6QiangUkh3B0jihzmGnNrRsQ=="], "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=="], "pg-cloudflare": ["pg-cloudflare@1.2.7", "", {}, "sha512-YgCtzMH0ptvZJslLM1ffsY4EuGaU0cx4XSdXLRFae8bPP4dS5xL1tNB3k2o/N64cHJpwU7dxKli/nZ2lUa5fLg=="],

View File

@@ -6,6 +6,7 @@ import "./src/env.js";
/** @type {import("next").NextConfig} */ /** @type {import("next").NextConfig} */
const config = { const config = {
serverExternalPackages: ['pg'],
}; };
export default config; export default config;

View File

@@ -69,7 +69,7 @@
"framer-motion": "^12.23.26", "framer-motion": "^12.23.26",
"lucide-react": "^0.525.0", "lucide-react": "^0.525.0",
"next": "^16.1.1", "next": "^16.1.1",
"pg": "^8.16.3", "pg": "8.13.1",
"react": "^19.2.3", "react": "^19.2.3",
"react-day-picker": "^9.12.0", "react-day-picker": "^9.12.0",
"react-dom": "^19.2.3", "react-dom": "^19.2.3",

View File

@@ -49,13 +49,29 @@ function SignInForm() {
} }
async function handleSocialSignIn() { 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); setLoading(true);
await authClient.signIn.sso({ try {
console.log("[SIGN IN PAGE] Calling authClient.signIn.sso with:", {
providerId: "authentik", providerId: "authentik",
callbackURL: callbackUrl, 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); setLoading(false);
} }
}
return ( return (
<div className="flex min-h-screen items-center justify-center relative overflow-hidden"> <div className="flex min-h-screen items-center justify-center relative overflow-hidden">

View File

@@ -6,64 +6,10 @@ import { ssoClient } from "@better-auth/sso/client";
/** /**
* Auth client for better-auth with SSO support. * Auth client for better-auth with SSO support.
* *
* Uses a Proxy pattern to ensure the client is only created in the browser. * Better-auth handles SSR internally, so we can just create the client directly.
* This prevents SSR/build-time errors while maintaining full type safety.
*/ */
// Create a typed client reference for type inference export const authClient = createAuthClient({
const _createClient = () => createAuthClient({
baseURL: process.env.NEXT_PUBLIC_APP_URL, baseURL: process.env.NEXT_PUBLIC_APP_URL,
plugins: [ssoClient()], plugins: [ssoClient()],
}); });
// Type for the full client including plugins
type AuthClientType = ReturnType<typeof _createClient>;
// 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;
},
});