From 260107c52af2cd3d082a490c2e0ffc8ab6709034 Mon Sep 17 00:00:00 2001 From: Ajax Davis Date: Thu, 1 Jan 2026 23:33:44 +1000 Subject: [PATCH] fix: simplify auth client and use window.location for redirects --- apps/web/src/app/(auth)/sign-in/page.tsx | 35 +++++++++++------------ apps/web/src/app/(auth)/sign-up/page.tsx | 36 +++++++++++------------- apps/web/src/lib/auth-client.ts | 4 ++- 3 files changed, 36 insertions(+), 39 deletions(-) diff --git a/apps/web/src/app/(auth)/sign-in/page.tsx b/apps/web/src/app/(auth)/sign-in/page.tsx index c8337fe..0fa9bb2 100644 --- a/apps/web/src/app/(auth)/sign-in/page.tsx +++ b/apps/web/src/app/(auth)/sign-in/page.tsx @@ -18,28 +18,25 @@ export default function SignInPage() { setLoading(true); try { - await signIn.email( - { - email, - password, - callbackURL: '/dashboard', - }, - { - onSuccess: () => { - router.refresh(); - router.push('/dashboard'); - }, - onError: (ctx) => { - console.error('Sign in error:', ctx.error); - setError(ctx.error.message || 'Failed to sign in'); - }, - } - ); - return; // onSuccess/onError handle the flow + const { data, error } = await signIn.email({ + email, + password, + }); + + if (error) { + console.error('Sign in error:', error); + setError(error.message || 'Failed to sign in'); + setLoading(false); + return; + } + + if (data) { + // Successfully signed in - redirect to dashboard + window.location.href = '/dashboard'; + } } catch (err) { console.error('Sign in exception:', err); setError('An unexpected error occurred'); - } finally { setLoading(false); } } diff --git a/apps/web/src/app/(auth)/sign-up/page.tsx b/apps/web/src/app/(auth)/sign-up/page.tsx index b55a7d1..53f4708 100644 --- a/apps/web/src/app/(auth)/sign-up/page.tsx +++ b/apps/web/src/app/(auth)/sign-up/page.tsx @@ -19,27 +19,25 @@ export default function SignUpPage() { setLoading(true); try { - await signUp.email( - { - name, - email, - password, - callbackURL: '/verify-email', - }, - { - onSuccess: () => { - router.push('/verify-email'); - }, - onError: (ctx) => { - console.error('Sign up error:', ctx.error); - setError(ctx.error.message || 'Failed to create account'); - }, - } - ); - return; // onSuccess/onError handle the flow + const { data, error } = await signUp.email({ + name, + email, + password, + }); + + if (error) { + console.error('Sign up error:', error); + setError(error.message || 'Failed to create account'); + setLoading(false); + return; + } + + if (data) { + // Successfully signed up - redirect to verify email page + window.location.href = '/verify-email'; + } } catch { setError('An unexpected error occurred'); - } finally { setLoading(false); } } diff --git a/apps/web/src/lib/auth-client.ts b/apps/web/src/lib/auth-client.ts index 1784745..421da8b 100644 --- a/apps/web/src/lib/auth-client.ts +++ b/apps/web/src/lib/auth-client.ts @@ -2,6 +2,8 @@ import { createAuthClient } from 'better-auth/react'; -export const authClient = createAuthClient(); +export const authClient = createAuthClient({ + baseURL: typeof window !== 'undefined' ? window.location.origin : undefined, +}); export const { signIn, signUp, signOut, useSession } = authClient;