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';
|
import { sendMail } from './resend';
|
||||||
|
|
||||||
export async function sendVerificationEmail(options: {
|
export async function sendVerificationEmail(options: {
|
||||||
email: string;
|
email: string;
|
||||||
token: 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({
|
await sendMail({
|
||||||
to: options.email,
|
to: options.email,
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { authClient } from '$lib/auth-client';
|
import { authClient } from '$lib/auth-client';
|
||||||
|
import { page } from '$app/state';
|
||||||
import Window from '$lib/components/containers/Window.svelte';
|
import Window from '$lib/components/containers/Window.svelte';
|
||||||
let email = $state('');
|
let email = $state('');
|
||||||
let password = $state('');
|
let password = $state('');
|
||||||
let error = $state('');
|
let error = $state('');
|
||||||
let rememberMe = $state(false);
|
let rememberMe = $state(false);
|
||||||
|
|
||||||
|
let verified = $derived(page.url.searchParams.get('verified') === 'true');
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
const { data, error: authError } = await authClient.signIn.email({
|
const { data, error: authError } = await authClient.signIn.email({
|
||||||
email,
|
email,
|
||||||
@@ -24,6 +27,13 @@
|
|||||||
|
|
||||||
<Window>
|
<Window>
|
||||||
<div>
|
<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}
|
{#if error}
|
||||||
<span class="text-red-600">{error}</span>
|
<span class="text-red-600">{error}</span>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user