Giter VIP home page Giter VIP logo

react-router-auth0's Introduction

react-router-auth0

Library to get started quickly with Auth0 using React and React-Router.

Installation

Install react-router-auth0 via yarn or npm.

$ yarn add react-router-auth0

Usage

Inside your router, add an AuthProvider and your routes.

import {
  PrivateRoute,
  LoginRoute,
  LogoutRoute,
  LandingPageRoute,
  AuthCallbackRoute,
  AuthProvider,
} from 'react-router-auth0'

const authedRoutes = (
  <AuthProvider
    domain={'your_domain.auth0.com'}
    clientId={'your_client_id'}
    audience={'https://your_domain.auth0.com/userinfo'}
  >
    <Switch>
      <LandingPageRoute exact path="/"
        landingUrl="http://my_landing_page"
        loggedInPath="/home" />

      <LoginRoute exact path="/login" />
      <LogoutRoute path='/logout' redirect='/' />
      <AuthCallbackRoute path='/auth0-callback' />

      <PrivateRoute
    </Switch>
</AuthProvider>
)

And add it to your main router like this:

const Router = () => {
  return (
    <Provider store={store}>
      <ConnectedRouter history={history}>

        {authedRoutes}

      </ConnectedRouter>
    </Provider>
  )
}

Component Descriptions:

AuthProvider: Main component which will bootstrap you auth0 client.

PrivateRoute: Any route the can only be accessed when logged in. If user is not logged in, redirects to the login route.

LoginRoute: Takes you to the auth0 lock screen

LogoutRoute: Handles auth0 logout and redirects you to the initial/landing page.

LandingPageRoute: When hit, will display any url passed through landingUrl prop when the user is not logged in. This can be a separate app/page, with or without react, which gives you the option of having one plain html/css lightweight landing page. If the user is logged in, redirects to url passed through loggedInPath prop.

AuthCallbackRoute: Route which Auth0 will callback once user logs in. Make sure to enable this url on your Auth0 management console.

LICENSE

MIT

react-router-auth0's People

Contributors

caiokf avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

react-router-auth0's Issues

Usage ?

Hello @caiokf
Can you please provide a short snippet of how to use your package please ?
Thanks !

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.