A complete authentication demo using @authrim/sveltekit. Deploy to Cloudflare Pages or run locally.
- Passkey Authentication - WebAuthn-based passwordless login
- Email Code Authentication - Passwordless email verification
- Social Login - Google, GitHub, Apple
- Session Management - View and revoke active sessions
- Passkey Management - Add and remove passkeys
- Server-side Validation - Protected routes with SSR
git clone https://github.com/authrim/example-sveltekit.git
cd example-sveltekit
pnpm installCopy the example environment file:
cp .env.example .envEdit .env with your Authrim credentials:
PUBLIC_AUTHRIM_ISSUER=https://your-tenant.authrim.com
PUBLIC_AUTHRIM_CLIENT_ID=your-client-idIn your Authrim Admin Dashboard, configure:
- Redirect URI:
http://localhost:5173/callback(for local development) - Allowed Origins:
http://localhost:5173
pnpm dev- Push your code to GitHub
- Go to Cloudflare Dashboard → Pages → Create a project
- Connect your GitHub repository
- Configure build settings:
- Framework preset: SvelteKit
- Build command:
pnpm build - Build output directory:
.svelte-kit/cloudflare
- Add environment variables:
PUBLIC_AUTHRIM_ISSUERPUBLIC_AUTHRIM_CLIENT_ID
pnpm build
npx wrangler pages deploy .svelte-kit/cloudflareUpdate your Authrim Admin settings:
- Redirect URI:
https://your-app.pages.dev/callback - Allowed Origins:
https://your-app.pages.dev
src/
├── app.d.ts # TypeScript declarations
├── app.html # HTML template
├── hooks.server.ts # Server hooks (auth middleware)
├── lib/
│ ├── auth.ts # Authrim client initialization
│ └── config.ts # Configuration helpers
└── routes/
├── +layout.svelte # Root layout with AuthProvider
├── +layout.server.ts # Server-side session loading
├── +page.svelte # Home page
├── login/
│ └── +page.svelte # Login page
├── signup/
│ └── +page.svelte # Sign up page
├── callback/
│ └── +page.svelte # OAuth callback handler
└── account/
├── +page.svelte # Account settings (protected)
└── +page.server.ts # Auth guard
pnpm dev- Start development serverpnpm build- Build for productionpnpm preview- Preview production buildpnpm check- Type-check the project
- User clicks "Continue with Passkey"
- Browser shows WebAuthn prompt
- On success, user is redirected to home
- User enters email address
- Verification code is sent to email
- User enters 6-digit code
- On verification, user is logged in
- User clicks a social provider button
- Popup opens for OAuth flow
- On completion, popup closes and user is logged in
This example uses the following components from @authrim/sveltekit/ui:
Card,Button,Input- Basic UI elementsEmailCodeForm- Email/code input flowSocialLoginButtons- Social provider buttonsPasskeyConditionalInput- Passkey input with conditional UIPasskeyList,PasskeyRegisterButton- Passkey managementSessionList- Session managementAuthError,Spinner- Feedback componentsOTPInput,ResendCodeButton- Code verification
Apache-2.0