mirror of
https://github.com/soconnor0919/beenvoice.git
synced 2026-02-04 15:56:31 -05:00
fix: remove proxy
This commit is contained in:
4
bun.lock
4
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=="],
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import "./src/env.js";
|
||||
|
||||
/** @type {import("next").NextConfig} */
|
||||
const config = {
|
||||
serverExternalPackages: ['pg'],
|
||||
};
|
||||
|
||||
export default config;
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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<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;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user