/supabase-tutorials

How to allow sign in only with specific domains in Supabase?

Restrict Supabase sign-ins to specific email domains. This guide shows you how to set up your project, configure email restrictions, and test sign-up functionality.

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 allow sign in only with specific domains in Supabase?

 

Step 1: Set Up a Supabase Project

 

• Navigate to the Supabase website and sign in or create an account.

• Once logged in, create a new project. Follow the necessary setup steps, such as selecting the server region and entering a name for your project.

 

Step 2: Configure Authentication

 

• In your Supabase project dashboard, navigate to the “Authentication” tab on the left sidebar.

• Click on “Settings” and then on the “Auth” tab.

 

Step 3: Enable Email Domain Restriction

 

• In the Email Auth section, locate the “Restrict sign-ups by email” option.

• Enter the allowed email domains in the provided field. Separate multiple domains with commas (e.g., example.com, company.org).

• Save your changes by clicking the “Save” button.

 

Step 4: Test the Email Domain Restriction

 

• Log out of the Supabase dashboard and attempt to sign up with an email address from one of the allowed domains to verify it works.

• Try signing up with an email address from a non-allowed domain to ensure the restriction is functioning.

 

Step 5: Implement Client-Side Email Sign-Up

 

• Use Supabase Client Libraries in your application. First, install the Supabase client for your environment. For example, using npm:


npm install @supabase/supabase-js

• Initialize the Supabase client in your application using your project-specific URL and public API key, which can be found in the Supabase dashboard under the “Settings” > “API” menu.


import { createClient } from '@supabase/supabase-js'

const supabaseUrl = 'https://xyzcompany.supabase.co'
const supabaseAnonKey = 'your-public-anon-key'

const supabase = createClient(supabaseUrl, supabaseAnonKey)

• Set up the client-side sign-up functionality to handle user registration:


async function signUpWithEmail(email, password) {
  const { user, session, error } = await supabase.auth.signUp({
    email: email,
    password: password,
  })

  if (error) {
    console.error('Error signing up:', error.message)
  } else {
    console.log('User signed up:', user)
  }
}

 

Step 6: Handle Sign-Up Confirmation and Email Verification

 

• Supabase automatically sends a confirmation email to new users. Ensure to test and verify that the confirmation flow works as expected.

• Optionally, customize the email templates used by Supabase from the “Settings” > “Email Templates” section in your dashboard.

 

Step 7: Monitor and Adjust Domain Restrictions (Optional)

 

• Monitor the sign-up traffic to ensure only users from the allowed domains are signing up.

• Modify the allowed domains list as needed, following the procedure in Step 3.

 

This step-by-step guide should help you effectively restrict sign-ins to specific domains using Supabase, ensuring better control over who can access your application based on their email domain.

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