- react >= 18
- react-redux >= 18
- @reduxjs/toolkit > 1.9
write this command after download requires packages
npm install --save react-http-provider
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
}
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;