fix auth: register redirect, password reset flow, GHL contact ID, session handling

- Fix register redirect bug where successful signup returned 400 instead
  of redirecting to /account/setup (use isRedirect() to re-throw redirects)
- Add error display to register page and fix Svelte 5 syntax (on:click)
- Add await to Google sign-in on login page and register page
- Fix logout to await signOut and redirect to /
- Implement full password reset flow:
  - Add sendResetPassword callback to auth.ts config
  - Create forgot-password page with email submission
  - Create reset-password page with one-time token validation
  - Guard reset page: redirect to / if no valid token in URL
- Add ghlContactId field to Profile model for future Go High Level integration
- Add Prisma migration for ghl_contact_id column
- Update register test to expect redirect instead of broken 400
This commit is contained in:
NeilClack
2026-07-07 08:30:27 -05:00
parent f566866a23
commit 4d4b2a1497
12 changed files with 271 additions and 71 deletions
@@ -0,0 +1,27 @@
import type { Actions } from './$types';
import { auth } from '$lib/auth';
import { fail } from '@sveltejs/kit';
export const actions: Actions = {
default: async ({ request }) => {
const data = await request.formData();
const email = data.get('email') as string;
if (!email) {
return fail(400, { error: 'Email is required.' });
}
try {
await auth.api.requestPasswordReset({
body: {
email,
redirectTo: '/reset-password'
}
});
return { success: true };
} catch (err) {
const message = err instanceof Error ? err.message : 'Failed to send reset email.';
return fail(400, { error: message });
}
}
};
+42
View File
@@ -0,0 +1,42 @@
<script lang="ts">
import { resolve } from '$app/paths';
import type { PageProps } from './$types';
let { form }: PageProps = $props();
</script>
<div class="mx-auto mt-12 max-w-md">
<h1 class="mb-6 text-2xl font-semibold text-gray-900">Forgot Password</h1>
{#if form?.success}
<div class="mb-4 rounded-lg border border-green-200 bg-green-50 p-4 text-green-700">
If an account with that email exists, we've sent a password reset link.
</div>
{/if}
{#if form?.error && !form?.success}
<div class="mb-4 rounded-lg border border-red-200 bg-red-50 p-3 text-red-700">
{form.error}
</div>
{/if}
<form method="POST" class="flex flex-col gap-4">
<input
type="email"
name="email"
placeholder="Email Address"
required
class="rounded-lg border border-gray-300 px-3 py-2 shadow-sm focus:border-blue-500 focus:ring-1 focus:ring-blue-500"
/>
<button
type="submit"
class="rounded-lg bg-blue-600 px-4 py-2 font-medium text-white transition-colors hover:bg-blue-700"
>
Send Reset Link
</button>
</form>
<a href={resolve('/login')} class="mt-4 block text-sm text-blue-600 hover:text-blue-800">
Back to Login
</a>
</div>