📖 Scenario: You are building a simple web app that lets users sign up and log in using their email and password. You will use Supabase, a cloud service that manages user accounts securely for you.
🎯 Goal: Create a Supabase project setup that enables email/password authentication. You will write code to initialize the Supabase client, and implement sign-up and sign-in functions.
📋 What You'll Learn
Initialize Supabase client with URL and anon key
Write a function to sign up users with email and password
Write a function to sign in users with email and password
💡 Why This Matters
🌍 Real World
Email/password authentication is a common way to let users securely create accounts and log in to web apps without managing passwords yourself.
💼 Career
Understanding how to set up authentication with cloud services like Supabase is essential for backend and full-stack developers building user-facing applications.
Progress0 / 3 steps
1
Initialize Supabase client
Create a constant called supabaseUrl with the value "https://xyzcompany.supabase.co" and a constant called supabaseAnonKey with the value "public-anonymous-key". Then create a constant called supabase by calling createClient(supabaseUrl, supabaseAnonKey).
Supabase
Hint
Use const to declare variables. The createClient function takes the URL and anon key as arguments.
2
Write sign-up function
Write an async function called signUpUser that takes email and password as parameters. Inside, call supabase.auth.signUp({ email, password }) and return the result.
Supabase
Hint
Use async function and await the signUp call with the email and password parameters.
3
Write sign-in function
Write an async function called signInUser that takes email and password as parameters. Inside, call supabase.auth.signInWithPassword({ email, password }) and return the result.
Supabase
Hint
Use async function and await the signInWithPassword call with the email and password parameters.
Practice
(1/5)
1. What is the primary purpose of using signUp in Supabase email/password authentication?
easy
A. To register a new user with email and password
B. To log in an existing user
C. To reset a user's password
D. To delete a user account
Solution
Step 1: Understand the function of signUp
The signUp method is used to create a new user account with an email and password.
Step 2: Differentiate from other authentication methods
Logging in uses signInWithPassword, not signUp. Password reset and deletion are separate actions.
Final Answer:
To register a new user with email and password -> Option A
Quick Check:
signUp = register new user [OK]
Hint: Remember: signUp means create account, not login [OK]
Common Mistakes:
Confusing signUp with signInWithPassword
Thinking signUp resets passwords
Assuming signUp deletes accounts
2. Which of the following is the correct syntax to sign in a user with email and password using Supabase?
easy
A. supabase.auth.login({ email: 'user@example.com', password: 'pass123' })
B. supabase.auth.signInWithPassword({ email: 'user@example.com', password: 'pass123' })
C. supabase.auth.signUp({ email: 'user@example.com', password: 'pass123' })
D. supabase.auth.authenticate({ email: 'user@example.com', password: 'pass123' })
Solution
Step 1: Identify the correct method for signing in
The method to sign in with email and password is signInWithPassword.
Step 2: Check the syntax format
The correct syntax uses an object with email and password keys inside signInWithPassword.
Final Answer:
supabase.auth.signInWithPassword({ email: 'user@example.com', password: 'pass123' }) -> Option B
Quick Check:
signInWithPassword = login syntax [OK]
Hint: signInWithPassword is for login, signUp is for registration [OK]
Common Mistakes:
Using signUp instead of signInWithPassword to login
Using non-existent methods like login or authenticate