Giter Site home page Giter Site logo

authoz's Introduction

React Authentication on Vercel

This JavaScript template demonstrates how to implement user authentication in React applications using Auth0. This template uses the React Router 6 library.

This template is based on a code sample is part of the "Auth0 Developer Center", a place where you can explore the authentication and authorization features of the Auth0 Identity Platform.

Quick Auth0 Set Up

First and foremost, if you haven't already, sign up for an Auth0 account to connect your application with the Auth0 Identity Platform.

Next, you'll connect your Single-Page Application (SPA) with Auth0. You'll need to create an application registration in the Auth0 Dashboard and get two configuration values: the Auth0 Domain and the Auth0 Client ID.

Get the Auth0 domain and client ID

  • Open the Applications section of the Auth0 Dashboard.

  • Click on the Create Application button and fill out the form with the following values:

    • Name: React Authentication on Vercel
    • Application Type: Single Page Web Applications
  • Click on the Create button.

Visit the "Register Applications" document for more details.

An Auth0 Application page loads up.

As such, click on the "Settings" tab of your Auth0 Application page, locate the "Application URIs" section, and fill in the following values:

  • Allowed Callback URLs: https://*.vercel.app/callback
  • Allowed Logout URLs: https://*.vercel.app
  • Allowed Web Origins: https://*.vercel.app

๐Ÿšจ๐Ÿšจ๐Ÿšจ WARNING: Once you have deployed this template, please replace https://*.vercel.app with your Vercel deploy URL for better security. ๐Ÿšจ๐Ÿšจ๐Ÿšจ

Scroll down and click the "Save Changes" button.

Next, locate the "Basic Information" section. You will need the "Domain" and "Client ID" values to deploy this template correctly.

Auth0 application settings to enable user authentication

Once you click the "Deploy" button, the Vercel deploy workflow will show up. On the "Configure Project" section, ensure that you use the following values for the "Required Environment Variables":

  • REACT_APP_AUTH0_DOMAIN is the value of the "Domain" field from the Auth0 settings.
  • REACT_APP_AUTH0_CLIENT_ID is the value of the "Client ID" field from the Auth0 settings.

After Deploy

Remember to replace https://*.vercel.app with your Vercel deploy URL in the Auth0 application settings.

Use the React Sample Application

Your Vercel deploy URL gives you access to the application.

If you want to learn how to implement user authentication in React step by step, check out the "React Authentication By Example" developer guide.

When you click on the "Log In" button, React takes you to the Auth0 Universal Login page. Your users can log in to your application through a page hosted by Auth0, which provides them with a secure, standards-based login experience that you can customize with your own branding and various authentication methods, such as logging in with a username and password or with a social provider like Facebook or Google.

Once you log in, visit the protected "Profile" page to see all the user profile information that Auth0 securely shares with your application using ID tokens.

Click on the "Log Out" button and try to access the Profile page.

If everything is working as expected, React redirects you to log in with Auth0.

Why Use Auth0?

Auth0 is a flexible drop-in solution to add authentication and authorization services to your applications. Your team and organization can avoid the cost, time, and risk that come with building your own solution to authenticate and authorize users. We offer tons of guidance and SDKs for you to get started and integrate Auth0 into your stack easily.

authoz's People

Contributors

pythonicboat avatar

Watchers

 avatar

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.