@jcbuisson/express-x 2.1.4 → 2.1.5
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 +1 -1
- package/src/common-hooks.mjs +11 -3
- package/src/server.mjs +1 -1
package/package.json
CHANGED
package/src/common-hooks.mjs
CHANGED
|
@@ -34,6 +34,14 @@ export function protect(field) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
|
|
38
|
+
class NotAuthenticatedError extends Error {
|
|
39
|
+
constructor(message) {
|
|
40
|
+
super(message)
|
|
41
|
+
this.code = 'not-authenticated'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
37
45
|
/*
|
|
38
46
|
* Throw an error for a client service method call when socket.data.expiresAt is missing or overdue
|
|
39
47
|
*/
|
|
@@ -47,10 +55,10 @@ export const isNotExpired = async (context) => {
|
|
|
47
55
|
if (now > expiresAtDate) {
|
|
48
56
|
// expiration date is met: clear socket.data & throw exception
|
|
49
57
|
context.socket.data = {}
|
|
50
|
-
throw new
|
|
58
|
+
throw new NotAuthenticatedError("Session expired")
|
|
51
59
|
}
|
|
52
60
|
} else {
|
|
53
|
-
throw new
|
|
61
|
+
throw new NotAuthenticatedError("no expiresAt in socket.data")
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
64
|
|
|
@@ -60,5 +68,5 @@ export const isNotExpired = async (context) => {
|
|
|
60
68
|
export const isAuthenticated = async (context) => {
|
|
61
69
|
// do nothing if it's not a client call from a ws connexion
|
|
62
70
|
if (!context.socket) return
|
|
63
|
-
if (!context.socket.data.user) throw new
|
|
71
|
+
if (!context.socket.data.user) throw new NotAuthenticatedError('no user in socket.data')
|
|
64
72
|
}
|
package/src/server.mjs
CHANGED