react-http-provider
v2.0.0
Published
Manaing http request with authentication using redux and redux toolkit
Downloads
12
Maintainers
Readme
react-http-provider
Installation
write this command after download requires packages
npm install --save react-http-provider
Usage
for using the library after install the package you should follow theses steps
1 - create store file for storing authentication states and use { authStoreBuilder } to build the store
import {authStoreBuilder} from 'react-http-provider';
const {AuthProvider,loginAction,logoutAction,useAuthDispatch,useAuthStore} = authStoreBuilder<{id:string,userName:string,token:string}>({
getToke() {
return localStorage.getItem('token');
},
removeToken(){
localStorage.removeItem('token');
},
setToken(token) {
localStorage.setItem('token',token);
},
});
export {
AuthProvider,
loginAction,
logoutAction,
useAuthDispatch,
useAuthStore
}
2 - create useHttp file to build custome http hook
import { logoutAction, useAuthDispatch } from "auth/store";
import { httpProviderBuilder } from "react-http-provider";
const useHttp = httpProviderBuilder({
baseUrl:'https://localhost:7160',
defaultApplyError(error){
console.error(error);
},
getToken(){
return localStorage.getItem('token');
},
refreshToken(respones) {
},
dispatchHook:useAuthDispatch,
logoutAction:logoutAction
});
export default useHttp;