react-axios-http-jwt
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

react-axios-http-jwt

Provides a react hook which uses axios-http-jwt to manage JWT authentication.

import axios from 'axios';
import { useClient } from 'react-axios-http-jwt';

const _client = const _client = axios.create({ withCredentials: true });

const onLogin = async (data: any): Promise<string> => {
  const response = await _client.post('/api/token/', data);
  return response.data.access;
};

const onLogout = async (): Promise<void> => {
  await _client.delete('/api/token/clear/');
};

const onRefresh = async (): Promise<string> => {
  const response = await _client.post(`/api/token/refresh/`);
  return response.data.access;
};

const client = useClient(config, onLogin, onLogout, onRefresh);

client.isAuthenticated // true when access token exists
client.isLoading // true when client attempting to load initial access token
client.axios // axios instance with access token header
client.login // login function
client.logout // logout function

Package Sidebar

Install

npm i react-axios-http-jwt

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

5.29 kB

Total Files

6

Last publish

Collaborators

  • gryevns