Code Monkey home page Code Monkey logo

remix-supabase-auth's Introduction

Remix Supabase Auth

Bare minimum and un-opinionated example using Remix to implement Supabase's email/password and oAuth

Features

  • Signin and Register using Supabase's email/password, Google, and Facebook auth
  • Change and reset password logic implemented
  • Integration for all oAuth providers that Supabase supports
  • Easily enable any oAuth provider - see extend section
  • Persist user with HTTP cookie
  • Refresh token logic implemented
  • Bare minimum and un-opinionated
  • main branch is Typescript but you can access JavaScript project in js branch

Quick Start

  • Create Supabase project (skip if you already have one):
    • Create Supabase account
    • Create an Organization and a project
  • Visit API settings page of your project by either going to https://app.supabase.io/project/<your-project-id>/settings/api or clicking on the Settings on the left sidebar > click on API under Project settings. You'll find your anon_key and URL on that page, which will be used in the next step.
  • Clone this example and rename/copy .env.example to .env and add SUPABASE_ANON_KEY, and SUPABASE_URL
  • Add your Google and Facebook client ID and secret to your Supabase project, follow the steps mentioned in the Supabase's documentation for Google and Facebook
  • Install npm dependencies by running npm i/npm install

Development

  • run the development server with npm run dev

What you'll get?

Register - Register using email/password or continue with Google/Facebook social authentications

Login - Login using email/password or continue with Google/Facebook social authentications. When logging in using a Google/Facebook account that is not registered in Supabase, Supabase will create a new account with that email

Forgot Password - Takes user's email and sends a password reset email using supabase.auth.api.resetPasswordForEmail

Auth Callback - Handles the callback from Supabase when oAuth providers are used to login or register. This route uses supabase.auth.onAuthStateChange to get the access and refresh tokens from the url and then it submits the FormData to create session on the server. Handles SIGNED_IN and PASSWORD_RECOVERY both

Profile - Only accessible when logged in, otherwise throws an error which is caught by Remix's CatchBoundary and asks user to login. Once logged in, it'll show the User object that is returned from Supabase

Change Password - Takes in password and confirm-password to update user's password. This route requires user to be logged in or being redirected from auth.callback.tsx with the auth cookie in the flow of PASSWORD_RECOVERY

Logout - Logs user out of the local session and Supabase session. It is an api/resource route because it doesn't export a JSX element

Extend Implementation

Add other oAuth providers
  • Simply add the client ID and secret to Supabase for the provider that you want to support.
  • In login.tsx and register.tsx add the <AuthProviderBtn provider={YourProvider} redirectTo={redirectTo} /> and that's it!

Questions?

Please feel free to hit me up on Twitter or opening an Issue

License

© 2022 Arpit Dalal. Released under MIT license

remix-supabase-auth's People

Contributors

arpitdalal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

remix-supabase-auth's Issues

Social logins return 404

Hey, I recently cloned your repo and set it up with the instructions provided, but when i click on either google / facebook login, i get the below error.

Screenshot 2022-03-15 at 17 02 52

The url after you click the google button is: http://localhost:3000/=https://<my-supabase-url>.supabase.co/auth/v1/authorize?provider=google&redirect_to=http%3A%2F%2Flocalhost%3A3000%2Fprofile

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.