# installation with npm
npm install --save auth0-js
# installation with yarn
yarn add auth0-js
The auth0.js library can also be retrieved from Auth0's CDN.
<script src="https://cdn.auth0.com/js/auth0/8.12.3/auth0.min.js"></script>
Add the following lines to your base code
// src/App.js
import React, { Component } from 'react';
import { Navbar, Button } from 'react-bootstrap';
import './App.css';
class App extends Component {
goTo(route) {
this.props.history.replace(`/${route}`)
}
login() {
this.props.auth.login();
}
logout() {
this.props.auth.logout();
}
componentDidMount() {
const { renewSession } = this.props.auth;
if (localStorage.getItem('isLoggedIn') === 'true') {
renewSession();
}
}
render() {
const { isAuthenticated } = this.props.auth;
return (
<div>
<Navbar fluid>
<Navbar.Header>
<Navbar.Brand>
<a href="#">Auth0 - React</a>
</Navbar.Brand>
<Button
bsStyle="primary"
className="btn-margin"
onClick={this.goTo.bind(this, 'home')}
>
Home
</Button>
{
!isAuthenticated() && (
<Button
bsStyle="primary"
className="btn-margin"
onClick={this.login.bind(this)}
>
Log In
</Button>
)
}
{
isAuthenticated() && (
<Button
bsStyle="primary"
className="btn-margin"
onClick={this.logout.bind(this)}
>
Log Out
</Button>
)
}
</Navbar.Header>
</Navbar>
</div>
);
}
}
export default App;
Auth0 is the easiest way for developers to integrate enterprise-grade authentication and identity management to any app.
SOC 2, HIPAA/BAA, EU/US Privacy Shield Framework, Open ID Certified.
Learn MoreContinuously reviewed and tested by external security experts. Strong password encryption and hashing algorithms, at rest and in transit.
Learn MoreContinuously reviewed and tested by external security experts. Strong password encryption and hashing algorithms, at rest and in transit.
Learn MoreUptime time in 3 different regions.
Learn MoreDeploy On-Premises or on Cloud on your data center or Auth0’s one.
Learn More