update bugs fix medicine, user record update-delete, user login

This commit is contained in:
2024-01-05 12:22:56 +07:00
parent 7c820547c0
commit 87f2788cdd
30 changed files with 505 additions and 96 deletions

View File

@@ -81,17 +81,19 @@ type AuthProviderProps = {
function AuthProvider({ children }: AuthProviderProps) {
const [state, dispatch] = useReducer(JWTReducer, initialState);
let location = useLocation();
const accessToken = getSession();
useEffect(() => {
const initialize = async () => {
(async () => {
try {
const accessToken = getSession();
// const accessToken = getSession();
if (accessToken) {
setSession(accessToken);
const response = await axios.get('/user');
const user = response.data;
dispatch({
type: Types.Initial,
payload: {
@@ -117,11 +119,10 @@ function AuthProvider({ children }: AuthProviderProps) {
},
});
}
};
initialize();
}, []);
})();
}, [accessToken]);
const login = async (email: string, password: string) => axios
.post('/login', { email, password })
.then((response) => {