Home

Auth with React

Installation

yarn add auth0-js

Auth0 file

import auth0 from 'auth0-js'; export default class Auth { auth0 = new auth0.WebAuth({ domain: 'domain', clientID: '...', redirectUri: '...', audience: 'domain/userinfo', responseType: 'token id_token', scope: 'openid' }); constructor() { this.login = this.login.bind(this); } login() { this.auth0.authorize(); } handleAuth() { this.auth0.parseHash((err, res) => { if (res && res.accessToken && res.idToken) { let expiresAt = JSON.stringify( authResults.expiresIn * 1000 + new Date().getTime() ); } }); } isAuthentication() { // handle with expiresAt value } }

Now we can just use the auth0 login.

In use

Repository

https://github.com/okeeffed/developer-notes-nextjs/content/auth/react-auth

Sections


Related