3.0.0 • Published 2 years ago

autologin-axios-client v3.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

autologin-axios-client

a quick wrapper around axios-auth-refresh for specific needs and defaults. for nodejs use.

does autologin on 401 response and redo the request.

Installation

npm i autologin-axios-client
# or
yarn add autologin-axios-client

Usage

const Axios = require('autologin-axios-client');
const axios = new Axios({
  baseUrl: 'https://example.com/api',
  refreshAuthLogic: (failedRequest: any) => Promise<any>,
  refreshAuthOptions: {
    // options for 'axios-auth-refresh'
  },
})
// start calling authorized api
axios.post('/users/delete-all');

or use the defaults and provide following env variables using dotenv module or other means.

const Axios = require('autologin-axios-client');
const axios = new Axios({
  baseUrl: 'https://example.com/api',
  refreshAuthInfo: {
    // change any of the defaults , use one or more
    // all are optional
    loginUrl: '/login',
    userField: 'email_or_mobile_number',
    passField: 'password',
    user: process.env.ALXC_USER,
    pass: process.env.ALXC_PASS,
    // it will send { email_or_mobile_number: user, password: pass }
    tokenPath: 'token',
    tokenType: 'Bearer',
  }
})
// start calling authorized api
axios.post('/users/delete-all');
3.0.0

2 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago