@vdocdk/meterportal-auth
v1.0.4
Published
meterportal auth helper
Downloads
126
Readme
Installation
npm i @vdocdk/meterportal-auth
- follow usage
Usage:
import MeterportalAuth from '@vdocdk/meterportal-auth';
const { login } = new MeterportalAuth();
const example = async () => {
//Login if auth needed.
await login({ username: '[email protected]', password: 'xxxxxx' });
};
example();
Persist token
import MeterportalAuth from '@vdocdk/meterportal-auth';
const { login, config } = new MeterportalAuth();
//load from localStorage
config.setToken(window.localStorage.getItem('token'));
config.setRefreshToken(window.localStorage.getItem('refresh-token'));
//event to update then tokens updated in config, then save in localstorage
config.on('setToken', (new_token) => window.localStorage.setItem('token', new_token));
config.on('refreshToken', (new_refresh_token) => window.localStorage.setItem('refresh-token',new_refresh_token));
//example
const example = async () => {
//Login if auth needed.
const user = await login({ emailAddress: '[email protected]', password: 'xxxxxx' });
if(!user) throw new Error('Wrong login');
};
example();
Author
vdoc ApS Support and help at vdoc.dk