-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6aa4d44
commit c2a2b25
Showing
20 changed files
with
3,531 additions
and
2,763 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import axios from "axios"; | ||
import PropTypes from "prop-types"; | ||
import React, { createContext, useState } from "react"; | ||
|
||
const SERVER_URL = process.env.REACT_APP_SERVER_URL; | ||
|
||
export const UserContext = createContext(null); | ||
|
||
export const UserProvider = ({ children }) => { | ||
const [user, setUser] = useState(null); | ||
|
||
// Fonction pour mettre à jour l'utilisateur | ||
const updateUser = (userData) => { | ||
setUser(userData); | ||
}; | ||
|
||
const logout = () => { | ||
axios | ||
.get(`${SERVER_URL}/logout`, { withCredentials: true }) | ||
.then((res) => { | ||
console.log(res); | ||
|
||
// Mettre à jour le contexte utilisateur | ||
updateUser(null); | ||
// Rediriger vers la page de connexion ou d'accueil | ||
window.location.href = "/login"; | ||
}) | ||
.catch((error) => { | ||
console.error("Erreur lors de la déconnexion", error); | ||
}); | ||
}; | ||
|
||
return ( | ||
<UserContext.Provider value={{ logout, updateUser, user }}> | ||
{children} | ||
</UserContext.Provider> | ||
); | ||
}; | ||
|
||
UserProvider.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
}; |
Oops, something went wrong.