1.0.3 • Published 7 years ago
mock-authentication-api v1.0.3
mock-authentication-api
Mock Authentication API is a utility module which provides straight-forward way to mocking authentication in your app. User needs to provide application's user store and use relevant APIs to manage authentication related operations
Installation
To install mock-authentication-api, use npm:
npm install mock-authentication-api
Usage
import * as AuthenticationApi from 'mock-authentication-api';
// setting configurations (netWorkLatency,userStore)
AuthenticationApi.configure(netWorkLatency,userStore);
// authenticating user
AuthenticationApi.authenticate(username,password);
// >> a promise
Example
import * as AuthenticationApi from 'mock-authentication-api';
const netWorkLatency = 1000;
const userStore = [
{id:1,username:'User1',password:'pass1'},
{id:2,username:'User2',password:'pass2'}
];
AuthenticationApi.configure(netWorkLatency,userStore);
// authenticating user
AuthenticationApi.authenticate('User1','pass1').then(user => {
// no password field on user response
console.log(`${user.username} logged in`)
}).catch(err => {
console.log(err);//Invalid User Credentials
});
API
mock-authentication-api.
configure(netWorkLatency, userStore)
- setting authentication configsauthenticate(username, password)
- authenticate the user according to provided username and password. Returns a promise.getUserStore()
- getting user storegetNetworkLatency()
- getting network latency