@stanlemon/server-with-auth 0.4.0 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/routes/auth.js +13 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stanlemon/server-with-auth",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "A basic express web server setup with authentication baked in.",
|
|
5
5
|
"author": "Stan Lemon <stanlemon@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/supertest": "^6.0.3",
|
|
37
37
|
"better-sqlite3": "^11.9.1",
|
|
38
38
|
"knex": "^3.1.0",
|
|
39
|
-
"nodemon": "^3.1.
|
|
39
|
+
"nodemon": "^3.1.10",
|
|
40
40
|
"supertest": "^7.1.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/routes/auth.js
CHANGED
|
@@ -105,18 +105,21 @@ export default function authRoutes({
|
|
|
105
105
|
|
|
106
106
|
router.get(ROUTES.LOGOUT, (req, res) => {
|
|
107
107
|
// This will happen if you are only using the JWT strategy
|
|
108
|
-
if (req.logout !== undefined) {
|
|
109
|
-
req.logout()
|
|
108
|
+
if (req.logout !== undefined && req.user !== undefined) {
|
|
109
|
+
return req.logout(() => {
|
|
110
|
+
if (req?.user?.id) {
|
|
111
|
+
eventEmitter.emit(EVENTS.USER_LOGOUT, req.user.id);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return res.status(401).json({
|
|
115
|
+
token: false,
|
|
116
|
+
user: false,
|
|
117
|
+
});
|
|
118
|
+
});
|
|
110
119
|
} else {
|
|
111
|
-
console.warn("Logout attempted, but
|
|
120
|
+
console.warn("Logout attempted, but unable to complete.");
|
|
121
|
+
return res.status(404).json({ error: "Not Found" });
|
|
112
122
|
}
|
|
113
|
-
|
|
114
|
-
eventEmitter.emit(EVENTS.USER_LOGOUT, req.user.id);
|
|
115
|
-
|
|
116
|
-
return res.status(401).json({
|
|
117
|
-
token: false,
|
|
118
|
-
user: false,
|
|
119
|
-
});
|
|
120
123
|
});
|
|
121
124
|
|
|
122
125
|
router.post(
|