1.3.9 • Published 7 years ago

authenticated-api v1.3.9

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

Authenticated API

Send API with auto renew access token logic

Notice: using same Babel config as create-react-app.

Usage

yarn install authenticated-api

Create TokenProvider:

const tokenProvider = new TokenProvider();

Create API:

const api = new Api({
  tokenProvider,
  prefix: process.env.REACT_APP_API_ENDPOINT,
});

(Somewhere in your app) after get access token and refresh token:

tokenProvider.setToken({ accessToken, refreshToken });

Now you can call authenticated request with API object:

const response = api.get('https://somewhere.com/api/something');

Options

Api

const api = new Api(options);

options have following keys:

  • tokenProvider: token provider.
  • prefix: host name
  • fetcher: the method to call for request, default is global window.fetch;
  • logging: true/false whether print debug log or not

TokenProvider

API object will expect TokenProvider to have the following methods:

  • getAccessToken(): return access token
  • renewToken() (async): renew the access token
1.3.9

7 years ago

1.3.8

7 years ago

1.3.7

7 years ago

1.3.6

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago