promisify-auth0
v9.6.0
Published
Make Auth0-js work with promises instead of callbacks.
Downloads
7
Maintainers
Readme
promisify-auth0-js
Promisifying wrapper around the Client Side Javascript toolkit for Auth0 API
Install
From npm
npm i --save promisify-auth0
Basic Usage
The package is mirroring the original auth0.js API. The only difference is that instead of NodeJS callback function style, promisify-auth0
allows you to get Promise<T>
instead which help avoid callback hell and play nicely with async/await
.
You will still need to create an original Auth0 objects and inject them into the corresponding wrapping types, something like this:
import { Authentication as NativeAuthentication } from 'auth0-js';
import { Authentication } from 'promisify-auth0';
const nativeAuthentication: NativeAuthentication = ...;
const authentication = new Authentication(nativeAuthentication);
const options = { realm: '...', audience: '...', username: '...', password: '...', scope: '...' };
authentication.login(options)
.then(loginResult => {
// ...
})
.catch(caughtError => {
// ...
});
The last piece of code could be rewritten in a more imperative style while maintaining the asyncronous execution model.
try {
const loginResult = await authentication.login(options);
// ...
} catch (caughtError) {
// ...
}
License and other
This code is distributed under MIT license.
Please respect the Code of Conduct.
Feel free to contribute.