From 4f30021a99d8c7e5ac0a09c6ff7179ccd2ec085f Mon Sep 17 00:00:00 2001
From: Anthony Correa
Date: Tue, 12 Mar 2024 08:36:05 -0500
Subject: [PATCH 1/2] add logout, team selection
---
src/controllers/team.js | 1 +
src/routes/auth.js | 7 +++++++
src/routes/index.js | 4 ++--
src/views/partials/navbar.hbs | 12 +++++++++++-
src/views/team/home.hbs | 2 +-
5 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/controllers/team.js b/src/controllers/team.js
index 9c927ec..af7a9da 100644
--- a/src/controllers/team.js
+++ b/src/controllers/team.js
@@ -5,6 +5,7 @@ utils = require("../lib/utils");
exports.getTeams = async (req, res, next) => {
const {layout} = req
const {user_id} = req.params
+ req.session.current_team_id = null
promise = teamsnap.loadTeams({'userId':user_id},
(err, items) =>{
teamsnapCallback(err,items);
diff --git a/src/routes/auth.js b/src/routes/auth.js
index 25b1b86..ee10f0a 100644
--- a/src/routes/auth.js
+++ b/src/routes/auth.js
@@ -149,4 +149,11 @@ router.get('/auth/teamsnap/session_storage', (req,res)=>{
}
)
+router.post('/logout', function(req, res, next){
+ req.logout(function(err) {
+ if (err) { return next(err); }
+ res.redirect('/');
+ });
+});
+
module.exports = {router, ensureLoggedIn};
diff --git a/src/routes/index.js b/src/routes/index.js
index 287c683..b006e7a 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -15,12 +15,12 @@ const membersController = require("../controllers/member");
router.use("/", ensureLoggedIn, (req,res,next) => {req.layout="layouts/main";req.promises=[];next();})
router.get("/", (req,res,next) => {
- if (!req.session.current_team){
+ if (!req.session.current_team_id){
res.redirect(`/user/${req.session.passport.user.id}/teams`)
next();
}
else {
- res.redirect(`/${req.session.current_team}/home`)
+ res.redirect(`/${req.session.current_team_id}/home`)
next();
}
});
diff --git a/src/views/partials/navbar.hbs b/src/views/partials/navbar.hbs
index dbe17e7..7a252ed 100644
--- a/src/views/partials/navbar.hbs
+++ b/src/views/partials/navbar.hbs
@@ -17,7 +17,17 @@
{{user.first_name}} {{user.last_name}}
- Logout
+