/supabase-tutorials

How to implement email verification in Supabase?

Step-by-step guide to implement email verification in Supabase. Set up and configure your project, SMTP, and auth for secure user registration.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to implement email verification in Supabase?

 

Step 1: Set Up a Supabase Project

 

  • Visit Supabase.io and click on the "Start your project" button to create a new account or log in if you already have an account.
  • Once logged in, create a new project by providing the necessary details like project name and organization.
  • After the project is created, you will be directed to the project dashboard.

 

Step 2: Configure Email Authentication

 

  • Navigate to the "Authentication" section from the side menu.
  • In the Authentication settings, ensure that "Email" is set as a provider.
  • Enable email confirmation to ensure verification is required for users. This setting is typically found under the "Configuration" or "Settings" tab within the authentication panel.
  • Make note of the SMTP settings if needed for custom email configurations.

 

Step 3: Set Up SMTP for Sending Emails

 

  • Configure SMTP settings to send emails from your custom domain. This involves entering SMTP host, port, username, and password of your email service provider.
  • If using default Supabase email settings, confirm they are working by checking for any default test email options in the dashboard.

 

Step 4: Build Your Frontend Application

 

  • In your frontend application code, integrate Supabase using the Supabase JavaScript client.
<script type="module">
  import { createClient } from '@supabase/supabase-js'
  
  const supabaseUrl = 'your-supabase-url'
  const supabaseKey = 'your-anon-key'
  const supabase = createClient(supabaseUrl, supabaseKey)
</script>

 

Step 5: Implement Email Registration

 

  • Implement a sign-up form for users to register with their email and password.
<form id="signup-form">
  <input type="email" id="email" placeholder="Email" required>
  <input type="password" id="password" placeholder="Password" required>
  <button type="submit">Sign Up</button>
</form>

<script>
  document.getElementById('signup-form').addEventListener('submit', async (event) => {
    event.preventDefault()
    const email = document.getElementById('email').value
    const password = document.getElementById('password').value
    const { user, error } = await supabase.auth.signUp({ email, password })
    if (error) { console.error('Error signing up:', error) }
  })
</script>

 

Step 6: Test the Email Verification

 

  • After implementing the code, test the registration and email verification process.
  • Sign up with an email address, then check the inbox for a verification email.
  • Confirm registration by following the link in the email, which should activate your account as verified.

 

Step 7: Validate Email Verification in Supabase

 

  • Return to the Supabase dashboard and navigate to the "Auth" section to manage users.
  • Ensure the user's status changes from "Unverified" to "Verified" upon successfully following the email verification link.

 

Step 8: Handle Email Verification Status in Your Application

 

  • Use Supabase authentication state to reflect user status in the UI (e.g., show prompts for email verification if the email is not verified).
const session = supabase.auth.session()

if (session && !session.user.email_confirmed_at) {
  console.log('Email not verified yet.')
} else {
  console.log('Email verified.')
}

 

This step-by-step guide should help you implement email verification for user authentication using Supabase. Make sure to consult Supabase's official documentation if more in-depth customization is required.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022