autheus

2.0.2 • Public • Published

autheus NPM version Build status

Image

A generic user auth/session module for front-end web apps.

Installation

Install the package with NPM:

$ npm install autheus

Usage

The package exposes an Autheus singleton class, making it ideal for web browser-based, single-page apps. It has a few utility methods, which can be used like so:

import {Autheus} from "autheus";
 
console.log(Autheus.isSignedIn); // -> false
console.log(Autheus.token);      // -> null
 
Autheus.signIn("fake-auth-token");
console.log(Autheus.isSignedIn); // -> true
console.log(Autheus.token);      // -> "fake-auth-token"
 
Autheus.signOut();
console.log(Autheus.isSignedIn); // -> false
console.log(Autheus.token);      // -> null

Furthermore, for those utilizing react-router, the package provides a getReactRouterHooks function to aide you in managing route transitions. Example:

let [requireSignIn, requireSignOut] = Autheus.getReactRouterHooks("/sign-in", "/sign-out");
let routes = (
  <Router history={hashHistory}>
    <Route path="/" component={App}>
      <IndexRoute component={Home} onEnter={requireSignIn} />
      <Route path="sign-in" component={SignIn} onEnter={requireSignOut} />
      <Route path="sign-out" component={SignOut} onEnter={requireSignIn} />
      <Route path="*" component={NotFound} />
    </Route>
  </Router>
);

Package Sidebar

Install

npm i autheus

Weekly Downloads

0

Version

2.0.2

License

MIT

Last publish

Collaborators

  • dstil-dev
  • dstil-admin