📖 Scenario: You are building a simple web app that lets users log in using a magic link sent to their email. This method avoids passwords and makes login easy and secure.
🎯 Goal: Create a Supabase project setup that enables magic link authentication for users. You will configure the initial user data, set up the authentication config, implement the login function using magic links, and finalize the authentication flow.
📋 What You'll Learn
Create a dictionary with a user email
Add a configuration variable for the redirect URL after login
Write a function to send a magic link using Supabase auth
Complete the authentication setup with the redirect URL
💡 Why This Matters
🌍 Real World
Magic link authentication is used in apps to simplify login without passwords, improving user experience and security.
💼 Career
Understanding magic link authentication is valuable for cloud developers working with modern authentication flows and user management.
Progress0 / 4 steps
1
Create initial user data
Create a dictionary called user_data with a single key email and value "user@example.com".
Supabase
Hint
Use curly braces to create a dictionary and set the key 'email' to the exact string 'user@example.com'.
2
Add redirect URL configuration
Add a variable called redirect_url and set it to "https://yourapp.com/welcome".
Supabase
Hint
Assign the exact URL string to the variable named redirect_url.
3
Implement magic link login function
Write a function called send_magic_link that takes email as a parameter and calls supabase.auth.sign_in_with_otp(email=email, options={"email_redirect_to": redirect_url}).
Supabase
Hint
Define a function with the exact name and parameter. Use the Supabase method sign_in_with_otp passing email as a named argument and options dict as the second.
4
Complete authentication setup
Call the function send_magic_link with the email from user_data to trigger sending the magic link.
Supabase
Hint
Use the exact function name and access the email from the user_data dictionary using the key 'email'.
Practice
(1/5)
1. What is the main purpose of magic link authentication in Supabase?
easy
A. Authenticate users using biometric data like fingerprints
B. Require users to enter a password and a code sent via SMS
C. Use social media accounts for login
D. Allow users to log in by clicking a link sent to their email without using a password
Solution
Step 1: Understand magic link authentication
Magic link authentication lets users log in by clicking a special link sent to their email, avoiding passwords.
Step 2: Compare options with this definition
Only Allow users to log in by clicking a link sent to their email without using a password describes login via email link without passwords, matching the magic link concept.
Final Answer:
Allow users to log in by clicking a link sent to their email without using a password -> Option D
Quick Check:
Magic link = login via email link without password [OK]
Hint: Magic link means login by email link, no password needed [OK]
Common Mistakes:
Confusing magic link with password or biometric login
Thinking magic link requires SMS codes
Assuming social login is magic link
2. Which is the correct way to call Supabase's magic link sign-in method in JavaScript?
easy
A. supabase.auth.signInWithPassword({ email: 'user@example.com' })
B. supabase.auth.signInWithOtp({ email: 'user@example.com' })
C. supabase.auth.signInWithMagicLink('user@example.com')
D. supabase.auth.loginWithOtp('user@example.com')
Solution
Step 1: Recall Supabase magic link method name
The correct method is signInWithOtp with an object containing the email.
Step 2: Match method and parameter format
supabase.auth.signInWithOtp({ email: 'user@example.com' }) uses signInWithOtp with an object { email: '...' }, which is correct syntax.
Final Answer:
supabase.auth.signInWithOtp({ email: 'user@example.com' }) -> Option B
Quick Check:
Method name and parameter object = supabase.auth.signInWithOtp({ email: 'user@example.com' }) [OK]
Hint: Use signInWithOtp with email in an object [OK]