Skip to content

Commit 47f6c6d

Browse files
committed
Added logout feature
1 parent b7ff72b commit 47f6c6d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Diff for: src/routers/user.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ router.post('/users/login',async (req, res) => {
6363
})
6464

6565
//
66-
// ─── LOG OUT ────────────────────────────────────────────────────────────────────
66+
// ─── LOG OUT OF CURRENT SESSION────────────────────────────────────────────────────────────────────
6767
//
6868

6969
router.post('/users/logout', auth, async (req, res) => {
@@ -73,11 +73,27 @@ router.post('/users/logout', auth, async (req, res) => {
7373
})
7474

7575
await req.user.save();
76+
res.send();
7677
} catch (e) {
7778
res.status(500).send();
7879
}
7980
})
8081

82+
//
83+
// ─── LOG OUT OF ALL SESSIONS ────────────────────────────────────────────────────
84+
//
85+
86+
router.post('/users/logoutAll', auth, async (req, res) => {
87+
try {
88+
var user = req.user;
89+
user.tokens = [];
90+
await user.save();
91+
res.status(500).send("Logged out of all sessions!");
92+
} catch (e) {
93+
res.status(400).send(e);
94+
}
95+
})
96+
8197
//
8298
// ─── PATCH ROUTE ────────────────────────────────────────────────────────────────
8399
//

0 commit comments

Comments
 (0)