Creating Authentication Pages
This guide will walk you through creating the necessary authentication pages for your SvelteKit application using Svelte Guardian, including sign-in, sign-up, password reset, and email verification.
Sign-In Page
Create a basic sign-in page at src/routes/signin/+page.svelte
:
Sign-Up Page
Create a sign-up page at src/routes/signup/+page.svelte
:
Password Reset Page
Create a password reset page at src/routes/reset-password/+page.svelte
:
Reset Your Password
{#if success}Enter your email address to receive a password reset link.
{/if} {:else if step === 'reset'}Create New Password
{#if success}Email Verification Page
Create an email verification page at src/routes/verify-email/+page.svelte
:
Email Verification
{#if success}Invalid or expired verification link. Please request a new one.
{#if resendSuccess}Please enter the verification code that was sent to your email.
Server-Side Request Handling
For some authentication operations, you’ll need server-side handlers. Here’s an example of a sign-in handler in src/routes/signin/+page.server.ts
:
Auth Utility Component
Create a reusable authentication status component at src/components/AuthStatus.svelte
:
Next Steps
After setting up these authentication pages, you should:
- Customize the styling to match your application’s design
- Add validation for form inputs
- Implement loading states and error handling
- Test the complete authentication flow
For more advanced authentication features, refer to the OAuth Providers and Two-Factor Authentication guides.