Miss any of our Open RFC calls?Watch the recordings here! »


0.3.5 • Public • Published

Auth JS

Auth flow

Request access token fail

Request api success

Access token expired and user session expired

Access token expired and create new token success

How to Use

Inject this code into your HTML file.

<script id="auth-sdk" src="../lib/EAuth.min.js" />
  var apiURL = <authServiceURL>;
  var eauth = new EAuth(apiURL);
  eauth.onTokenReceived = function(data) {
    console.log('data', data);
    // Save your token here
  eauth.onTokenReceivedError = function(error) {
    console.log('data', data);

Your need to replace:

  • <authServiceURL> - URL to auth service
  • <loginURL> - Redirect URL when you get response 401
  • <authDataHandler> - Data handler, usually use to store access token to redux store
  • <authDataErrorHandler> - Beside redirect to login page, what do you want to do? Usually use to handle status code !== 401

Auth instance method

  • constructor(authURL) - Create Auth instance with auth service URL
  • setRedirectLoginURL - Set redirect link to login page. if requestToken or forceRequestToken response status is 401, it will redirect to login page
  • requestToken - Request token from local storage and validate it. If invalidate, call to Auth service to get new
  • forceRequestToken - call to Auth service to get new access token
  • onTokenReceived - Callback to handle access token return by requestToken or forceRequestToken
  • onTokenReceivedError - Callback to handle error return by requestToken or forceRequestToken. Note: if status is 401, it will redirect to login page.



  • npm run build - produces production version of your library under the lib folder
  • npm run diagrams - Re draw diagrams
  • npm run dev - produces development version of your library and runs a watcher
  • npm run test - well ... it runs the tests :)
  • npm run test:watch - same as above but in a watch mode


  pushstate-server ./

Go to http://localhost:9000/demo/




npm i eh-auth

DownloadsWeekly Downloads






Last publish


  • avatar
  • avatar