Spaces:
Sleeping
Sleeping
File size: 1,198 Bytes
750887b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import { createContext, useContext, useEffect, useState } from "react";
const AuthContext = createContext();
export function AuthProvider({ children }) {
const [isAuthenticated, setIsAuthenticated] = useState(false); // para saber si el usario esta autentificado
const [user, setUser] = useState({ name: "mocos" }); // la informacion util del usario como nombre, usarname, correo, etc.
const [isRegisterGlucosa, setIsRegisterGlucosa] = useState(false); // saber si el usario ya ha registrado su glucosa el dia actual
const [update, setUpdate] = useState(false);
const changeAuthenticat = () => {
setIsAuthenticated(!isAuthenticated);
};
const changeUser = (newUser) => {
setUser(newUser);
};
const confirmRegisterGlucosa = () => {
setIsRegisterGlucosa(!isRegisterGlucosa);
};
useEffect(() => {
setUpdate(false);
}, [update, user]);
return (
<AuthContext.Provider
value={{
isAuthenticated,
user,
isRegisterGlucosa,
changeAuthenticat,
changeUser,
confirmRegisterGlucosa,
}}
>
{children}
</AuthContext.Provider>
);
}
export const useAuth = () => useContext(AuthContext);
|