Here is the rewritten article:

Building a Secure Login System with React and Supabase

When it comes to building a login system, developers often face a daunting task. However, with the right tools, it can be a breeze. In this article, we’ll explore how to create a secure login system using React and Supabase, an open-source Firebase alternative.

Getting Started with Supabase and React

To begin, let’s create a new React project using Vite. Run the following command in your terminal:

npm init vite@latest supabase-auth

Next, install the required dependencies by running:

npm install

Now, let’s update our App.jsx file with the following code:

import { SupabaseClient } from '@supabase/supabase-js';

const supabaseUrl = import.meta.env.VITE<em>SUPABASE</em>URL;
const anonKey = import.meta.env.VITE<em>SUPABASE</em>ANON_KEY;

const supabase = SupabaseClient(supabaseUrl, anonKey);

function App() {
  return (
    <div className="container">
      <supabase-auth.ui.providers
        providers={['google', 'facebook', 'github']}
      />
    </div>
  );
}

export default App;

In this code, we’ve added the Supabase Auth UI and centered it using CSS. We’ve also specified the providers we want to use, which are Google, Facebook, and GitHub.

Configuring Supabase for React

To use Supabase in our React application, we need to create a project in the Supabase dashboard. Once we’ve created the project, we can get our Supabase URL and Anon Key from the API settings.

We’ll add these values to our .env file:

VITE_SUPABASE_URL=myvalueissomevalue
VITE_SUPABASE_ANON_KEY=myanonkey

Now, we can start our development server by running npm run dev. This will start the server at http://localhost:5173/.

Email Authentication

When we log in, we’ll see a sign-up functionality. We can create a new account and use it to log in. After creating and entering our credentials, we’ll be directed to a page with a “Logged in!” message and a Sign out button.

Google Auth Configuration

To configure Google Auth, we need to create a new project in the Google Cloud Console. We’ll search for OAuth and go to the OAuth consent screen, where we’ll get our client ID and secret key.

We’ll add these values to our Supabase project by going to the Authentication section, clicking on Providers, and enabling Google. We’ll paste our client ID and secret key, as well as our redirect URL.

Facebook Auth Configuration

The process for configuring Facebook Auth is similar. We’ll create a new app on the Facebook Developer Platform, specify our platform and app name, and get our App ID and App secret.

We’ll add these values to our Supabase project by going to the Authentication section, clicking on Providers, and enabling Facebook. We’ll paste our App ID and App secret, as well as our redirect URL.

GitHub Auth Configuration

Finally, we’ll configure GitHub Auth by creating a new application on the GitHub Developer Platform. We’ll get our client ID and secret key, and add them to our Supabase project.

Conclusion

That’s it! We’ve successfully created a login system with email, Google, Facebook, and GitHub authentication using React and Supabase. With Supabase’s pre-made authentication UI and easy integration with social media platforms, building an authentication system has never been easier.

Leave a Reply