Skip to content

Commit

Permalink
Merge pull request #50 from WildCodeSchool-2023-09/logout
Browse files Browse the repository at this point in the history
rajout du bouton logout et quelque modif
  • Loading branch information
jujuck authored Feb 7, 2024
2 parents 81f0f4a + 217ac57 commit ae53303
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion backend/src/controllers/userControllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const login = async (req, res, next) => {
res
.cookie("auth", createToken(user), { httpOnly: true })
.status(200)
.json({ id: user.id, email: user.email, roleId: user.role_id });
.json({ id: user.id, email: user.email, role_id: user.role_id });
} else {
res.sendStatus(403);
}
Expand Down
14 changes: 9 additions & 5 deletions backend/src/middleware/checkCredentials.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const { verifyToken } = require("../services/jwt");

const checkCredentials = (req, res, next) => {
const decode = verifyToken(req.cookies.auth);
if (decode.role_id !== null) {
req.user = decode;
next();
if (req.cookies.auth) {
const decode = verifyToken(req.cookies.auth);
if (decode.role_id !== null) {
req.user = decode;
next();
} else {
res.sendStatus(403);
}
} else {
res.sendStatus(403);
next();
}
};

Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function NavBar() {
await connexion.post("/logout");
logout();
navigate("/");
window.location.reload();
} catch (err) {
console.error("Erreur lors de la déconnexion :", err);
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/contexts/auth.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export const useAuthContext = () => useContext(AuthContext);
export function AuthProvider({ children }) {
const [connected, setConnected] = useState("not connected");

function logout() {
const logout = () => {
setConnected("not connected");
}
};

const contextValue = useMemo(
() => ({ connected, setConnected, logout }),
Expand Down

0 comments on commit ae53303

Please sign in to comment.