Socket
Socket
Sign inDemoInstall

auth0-react

Package Overview
Dependencies
Maintainers
3
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auth0-react

Drop-in auth0 integration for react apps


Version published
Weekly downloads
759
increased by8.58%
Maintainers
3
Weekly downloads
 
Created
Source

auth0-react

NOTE: Very much a WIP

Drop-in auth0 integration for react apps

Example usage

your-app/src/routes.js

Use Auth0CallbackRoute to catch Auth's redirect after a login, with optional success and error redirects

import React, { ReactPropTypes } from 'react'
import { Router, Route, Switch } from 'react-router-dom'
import { Auth0Provider, Auth0CallbackRoute } from 'auth0-react'

const AUTH0_CONFIG = {
  audience: ...
  domain: ...
  clientId: ...
  callbackUrl: ...
  logoutUrl: ...
}

export default () =>
  <Router>
    <Auth0Provider {...AUTH0_CONFIG}>
      <Switch>
        { /* .... your routes .... */ }
        
        <Route path='/login' component={Login} />

        { /* Auth0 redirects here after login */ }
        <Auth0CallbackRoute path='/auth/callback' successTo='/' errorTo='/login' />
        
        { /* .... your routes .... */ }
      </Switch>
    </Auth0Provider>
  <Router>

your-app/src/LoginRoute.js

Provide a login button

import React from 'react'
import { useAuth0 } from 'auth0-react'

export default () => {
  const { login } = useAuth0()

  return (
    <div>
      <p>Welcome to Some App</p>
      <button onClick={login}>Log In</Button>
    </div>
  )
}

your-app/src/Header.js

Display current user's email and provide a logout button

import React from 'react'
import { useAuth0 } from 'auth0-react'

export default () => {
  const { logout, currentUser } = useAuth0()

  return (
    <div>
      <p>{currentUser.email}</p>
      <button onClick={logout}>Log Out</Button>
    </div>
  )
}

How to deploy

  1. Make sure you have access to the ollieorder organization on npm
  2. Run yarn publish
  3. Specify a carefully chosen semantic version number for your deploy. During the publish step, yarn will update the version number and make a commit for you. It also generates the docs for you, but those need to be commited manually.
  4. Commit the generated documentation git commit
  5. Push up the latest changes including the generated tags: git push --follow-tags master

FAQs

Package last updated on 23 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc