autheus
v2.0.2
Published
A generic user auth/session module for front-end web apps.
Downloads
2
Readme
autheus
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>
);