Features/Auth
Magic Link
Configuring Magic Link (Email) authentication using Auth.js v5.
This guide explains the setup for Magic Link (passwordless email) authentication in StarterKitPro using Auth.js v5.
Default Feature
Magic Link authentication is included and configured by default in StarterKitPro.
Prerequisites
- Email Sending Setup: Magic Link relies on sending emails. Ensure you have configured an email provider (like Resend or SendGrid) and it's working correctly.
- Database Setup: Auth.js requires a database adapter (like Prisma) to store user and verification token information. Ensure your database is set up. See Database Setup.
1. Environment Variables
Ensure these core Auth.js variables are set in your .env.local
file:
AUTH_SECRET
: A random string (at least 32 characters recommended) used for encryption. Generate one usingopenssl rand -base64 32
. Do not commit this file.AUTH_URL
: Your application's canonical URL.- Include the necessary API keys and settings for your chosen email provider.
Default Feature
In lib/app-config.ts
file, add an from field to resend.fromNoReply (usually
noreply@mail.yourdomain.com)
3. Rate Limiting (Recommended)
To prevent abuse (users requesting too many magic links), it's highly recommended to implement rate limiting on the verification email sending process.
- Refer to the Rate Limiting documentation for guidance on how to set this up, potentially using a service like Upstash.
4. Testing
- Start Server: Run
npm run dev
. - Navigate to Sign In: Go to your application's sign-in page.
- Enter Email: Type your email address into the designated field and submit.
- Check Email: You should receive an email with a sign-in link.
- Click Link: Click the link in the email. You should be redirected back to your application and logged in.
Magic Link authentication is now ready to use!