AutorÃa | Ultima modificación | Ver Log |
import { useDispatch, useSelector } from "react-redux";
import { useApi } from "./useApi";
import { getCredentials } from "@services/auth";
import { setCrendentials } from "@store/auth/auth.actions";
export function useCredentials() {
const { is_logged_in } = useSelector((state) => state.auth);
const dispatch = useDispatch();
const { data, loading, error, execute } = useApi(getCredentials, {
onSuccess: (credentials) => {
window.localStorage.setItem("jwt", credentials.jwt);
dispatch(setCrendentials(credentials));
},
onError: (error) => {
console.log(error);
},
});
useEffect(() => {
execute();
}, [is_logged_in]);
return { credentials: data, loading, error };
}