@rpcbase/server 0.98.0 → 0.99.0
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/cli/run_native.js +1 -1
- package/express/session_middleware.js +4 -2
- package/mongoose/index.js +0 -3
- package/package.json +1 -1
- package/src/auth/check_session.js +13 -2
- package/src/models/User.js +3 -0
package/cli/run_native.js
CHANGED
|
@@ -155,7 +155,7 @@ const run_native = (infrastructure_dir, proj_prefix, args) => {
|
|
|
155
155
|
let prefix = ""
|
|
156
156
|
// avoid printing [server] server:
|
|
157
157
|
if (!args.verbose && item.name !== "server") {
|
|
158
|
-
prefix = `${colors.green(item.name)}
|
|
158
|
+
prefix = `${colors.green(item.name)}:`
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
ps.stdout.on("data", (data) => {
|
|
@@ -5,14 +5,16 @@ const validator = require("validator")
|
|
|
5
5
|
const {createClient} = require("redis")
|
|
6
6
|
const redis_store = require("connect-redis")(session)
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
const {SESSION_STORE_PORT, CONTAINER_MODE} = process.env
|
|
10
|
+
|
|
8
11
|
const log = debug("rb:session")
|
|
12
|
+
// log.useColors = true
|
|
9
13
|
|
|
10
14
|
// WARNING:
|
|
11
15
|
// https://stackoverflow.com/questions/70867229/error-connection-timeout-when-connecting-to-redis-docker-instance
|
|
12
16
|
// https://github.com/redis/node-redis/issues/1656/
|
|
13
17
|
|
|
14
|
-
const {SESSION_STORE_PORT, CONTAINER_MODE} = process.env
|
|
15
|
-
|
|
16
18
|
if (typeof SESSION_STORE_PORT === "string" && !validator.isPort(SESSION_STORE_PORT)) {
|
|
17
19
|
throw new Error("expected SESSION_STORE_PORT to be a valid port number")
|
|
18
20
|
}
|
package/mongoose/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/* @flow */
|
|
2
2
|
const debug = require("debug")
|
|
3
3
|
|
|
4
|
+
const User = require("../models/User")
|
|
4
5
|
|
|
5
6
|
const log = debug("rb:auth:check_session")
|
|
7
|
+
log.useColors = true
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
const check_session = async(payload, ctx) => {
|
|
@@ -10,14 +12,23 @@ const check_session = async(payload, ctx) => {
|
|
|
10
12
|
|
|
11
13
|
log("session:", req.session)
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
let is_signed_in = !!req.session.user_id
|
|
14
16
|
|
|
15
17
|
log("is_signed_in:", is_signed_in)
|
|
16
18
|
|
|
19
|
+
// check if user exists
|
|
20
|
+
const user = await User.findOne({_id: req.session.user_id}, {_id: 1})
|
|
21
|
+
if (!user) {
|
|
22
|
+
is_signed_in = false
|
|
23
|
+
req.session.destroy(/* TODO: this should take callback */)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// TODO: check if user is disabled or blocked
|
|
27
|
+
|
|
17
28
|
return {
|
|
18
29
|
status: "ok",
|
|
19
30
|
is_signed_in,
|
|
20
|
-
user_id: req.session
|
|
31
|
+
user_id: req.session?.user_id,
|
|
21
32
|
}
|
|
22
33
|
}
|
|
23
34
|
|