Magic Link Authentication
What is Magic Link?
Magic Link is a secure and user-friendly authentication method that simplifies the login process by sending users a unique link via email. Instead of relying on traditional passwords, Magic Link allows users to access their accounts by clicking on the provided link, eliminating the need to remember and manage passwords.
Benefits of Magic Link Authentication
-
Simplicity: Users can log in with a single click, reducing friction and enhancing the user experience.
-
Security: Magic Links are time-sensitive and unique to each login attempt, adding an extra layer of security to the authentication process.
-
No Password Hassles: Eliminates the need for users to remember and manage passwords, reducing the likelihood of forgotten passwords and password-related issues.
Enabling Magic Link Authentication in Full-Stack-Kit
To allow users to authenticate to your app using Magic Link, follow these steps in Full-Stack-Kit:
-
Open the
/app/app.config.ts
file. -
Enable the
auth.providers.email
provider by settingenabled
totrue
:/app/app.config.tsauth: { providers: { email: { enabled: true, }, }, // ... other configuration options },
-
Save the file.
Setting up Email Server for Magic Link Authentication
Note: Full-Stack-Kit uses Resend.com to send emails by default. It's easy to set
up and has a great free plan. If you prefer to use your own email server, you can configure the
sendTransactionalEmail
function located in the lib/email/send-transactional-email.tsx
file
accordingly. However, we recommend using Resend.com
for its simplicity and effectiveness.
To set up Resend.com, follow these steps:
-
Create a free account at Resend.com (opens in a new tab).
-
Once you've created your account, login to your Resend.com dashboard
-
Click on the API Keys tab.
-
Create and Copy your API Key.
-
Open the
.env.local
file. -
Find the
# Resend
section and paste your API Key as the value of the RESEND_API_KEY variable:
# Resend
RESEND_API_KEY=your_api_key
- Save the file.
Testing Magic Link Authentication
To test Magic Link authentication, follow these steps:
- Go to the login page of your app.
- Enter your email address and click on the Sign In With Email button.
- Check your email inbox for the Magic Link email.
- Click on the Magic Link in the email.
- You should be logged in to your app.
Now your app is ready to authenticate user using Magic Link. If you have any questions or run into issues, refer to the documentation or reach out to our community for assistance.