auth: show email verified banner on login page after verification
- Append ?verified=true to callbackURL in verification link - Login page reads query param and shows green success banner when user lands after email verification
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { BASE_URL } from '$env/static/private';
|
||||
import { BETTER_AUTH_URL } from '$env/static/private';
|
||||
import { sendMail } from './resend';
|
||||
|
||||
export async function sendVerificationEmail(options: {
|
||||
email: string;
|
||||
token: string;
|
||||
}) {
|
||||
const verificationUrl = `${BASE_URL}/api/auth/verify-email?token=${options.token}&callbackURL=/login`;
|
||||
const verificationUrl = `${BETTER_AUTH_URL}/api/auth/verify-email?token=${options.token}&callbackURL=/login?verified=true`;
|
||||
|
||||
await sendMail({
|
||||
to: options.email,
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { authClient } from '$lib/auth-client';
|
||||
import { page } from '$app/state';
|
||||
import Window from '$lib/components/containers/Window.svelte';
|
||||
let email = $state('');
|
||||
let password = $state('');
|
||||
let error = $state('');
|
||||
let rememberMe = $state(false);
|
||||
|
||||
let verified = $derived(page.url.searchParams.get('verified') === 'true');
|
||||
|
||||
async function handleSubmit() {
|
||||
const { data, error: authError } = await authClient.signIn.email({
|
||||
email,
|
||||
@@ -24,6 +27,13 @@
|
||||
|
||||
<Window>
|
||||
<div>
|
||||
{#if verified}
|
||||
<div
|
||||
class="mb-4 rounded-lg border border-green-200 bg-green-50 p-4 text-green-700"
|
||||
>
|
||||
Your email has been verified. You can now log in.
|
||||
</div>
|
||||
{/if}
|
||||
{#if error}
|
||||
<span class="text-red-600">{error}</span>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user