npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@atayahmet/react-axios-token-provider

v1.0.5

Published

React Axios Token Provider package is a make easy what repetitive processes.

Downloads

47

Readme

Build Status

React Axios Token Provider

React Axios Token Provider package is a make easy what repetitive processes. For example handle access token or refresh token management process easly.

Why

It can be preferred to reduce repetitive practices for authentication operations in projects.

Features

  • Access token management
  • Refresh token management
  • Csrf/Xsrf token management

Installation

Use the package manager yarn or npm to install react-axios-token-provider

$ npm i @atayahmet/react-axios-token-provider --save
$ yarn add @atayahmet/react-axios-token-provider

Basic Usage

import AxiosTokenProvider from '@atayahmet/react-axios-token-provider';
import axios from 'axios';

function App() {
  return (
    <AxiosTokenProvider instance={axios}>
      <div>
        <h1>Hello World!</h1>
      </div>
    </AxiosTokenProvider>
  );
}

Props

| name | type | default | description | | ------------------- | ------------- | ----------------------------------------------- | ------------------------------------------------ | | instance | AxiosInstance | AxiosInstance | An axios instance. | | init | Function | - | Initializer helper function. | | refreshToken | Boolean | false | Activation of refresh token. | | csrfToken | Boolean | false | Activation of csrf token. | | initialAccessToken | String | - | Initial access token. | | initialRefreshToken | String | - | Initial refresh token. | | initialCsrfToken | String | - | Initial csrf token. | | tokenPathVariants | IPathVariants | Default Path Variants | The paths of all type tokens in response object. | | statusCallbacks | Object | - | Specific events of status codes. |

instance

You need to define your axios instance you want to manage. If no instance is defined, no action will be taken. A log is written to the console at the warning level.

Example:

import axios from 'axios';

<AxiosTokenProvider instance={axios}>
  <App />
</AxiosTokenProvider>;

init

The init prop is a inilizer function for provide extra config to developers.

Example:

function initializer(instance) {
  instance.baseURL = 'https://reqres.in/api';
}
<AxiosTokenProvider init={initializer} instance={axios}>
  <App />
</AxiosTokenProvider>

tokenPathVariants

You can define all token (access, refresh or csrf) paths to this prop.

Example:

<AxiosTokenProvider
  tokenPathVariants={{
    accessToken: ['headers.X-Access-Token', 'data.tokens.access_token'],
    refreshToken: ['headers.X-Refresh-Token', 'data.tokens.refresh_token'],
  }}
></AxiosTokenProvider>

Default Path Variants

{
  accessToken: ['headers.x-access-token', 'data.access_token'],
  csrfToken: ['headers.x-csrf-token', 'headers.x-xsrf-token'],
  refreshToken: ['headers.x-refresh-token', 'data.refresh_token'],
}

statusCallbacks

You can define specific callbacks to response status codes.

Example:

function unauthorized(response) {
  location.href = '/login';
}

function forbidden(response) {
  // do something
}
<AxiosTokenProvider
  statusCallbacks={{
    401: unauthorized,
    403: forbidden,
  }}
></AxiosTokenProvider>

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT