/supabase-tutorials

How to validate email format in Supabase auth?

Learn how to validate email format in Supabase Auth with this step-by-step guide to create a project, configure settings, integrate validation, and test user sign-ups.

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 validate email format in Supabase auth?

 

Step 1: Create a New Project in Supabase

 

  • Head over to the Supabase website and log in or create an account.
  • Once logged in, create a new project by selecting "New Project".
  • Fill in the required details like the project name, organization, database password, etc., then click "Create New Project".

 

Step 2: Configure the Auth Settings

 

  • Navigate to the "Authentication" tab on the left-hand menu of your Supabase dashboard.
  • In the "Settings" tab, scroll to "Email Auth" and ensure it is enabled.
  • Configure any additional settings as needed, such as email verification.

 

Step 3: Set Up Environment for Your Project

 

  • Ensure you have Node.js installed on your machine.

  • Create a new directory for your project and initialize it using npm:

    ```shell
    mkdir my-supabase-app
    cd my-supabase-app
    npm init -y
    ```

  • Install the necessary Supabase client library:

    ```shell
    npm install @supabase/supabase-js
    ```

 

Step 4: Initialize Supabase Client

 

  • Create a new file in your project directory, such as supabaseClient.js.

  • Initialize the Supabase client with your API URL and Key from your Supabase dashboard:

    
    import { createClient } from '@supabase/supabase-js';
    
    const supabaseUrl = 'https://your-project-ref.supabase.co';
    const supabaseAnonKey = 'your-anonymous-public-api-key';
    
    export const supabase = createClient(supabaseUrl, supabaseAnonKey);
    

 

Step 5: Implement Email Format Validation

 

  • Create a new JavaScript file, for example, validateEmail.js.

  • Write a function to validate email format before passing it to Supabase:

    
    function validateEmail(email) {
        const emailRegex = /^[^\s@]+@[^\s@]+.[^\s@]+$/;
        return emailRegex.test(email);
    }
    
    // Example usage
    const email = '[email protected]';
    if (validateEmail(email)) {
        console.log('Email is valid');
    } else {
        console.log('Email is invalid');
    }
    

 

Step 6: Integrate with Supabase Auth Function

 

  • Combine email validation with user sign-up functionality:

  • Modify your script to integrate Supabase authentication. In your app.js file:

    
    import { supabase } from './supabaseClient';
    import { validateEmail } from './validateEmail';
    
    async function signUpUser(email, password) {
        if (!validateEmail(email)) {
            console.log('Invalid email format.');
            return;
        }
    
        const { user, 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);
        }
    }
    
    // Example usage
    signUpUser('[email protected]', 'securePassword123');
    

 

Step 7: Test Your Implementation

 

  • Run your application to test email validation and user sign-up:

    ```shell
    node app.js
    ```

  • Ensure that your application correctly validates email formats and signs up users through Supabase Auth with proper error handling.

 

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