@go-mailer/jarvis 3.1.0 → 3.1.1
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/lib/middlewares/auth.js +10 -1
- package/package.json +1 -1
package/lib/middlewares/auth.js
CHANGED
|
@@ -20,6 +20,15 @@ const extract_token = (headers) => {
|
|
|
20
20
|
return token;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
const extract_tenant_id = (request) => {
|
|
24
|
+
const { params, query } = request
|
|
25
|
+
let tenant_id = { $exists: true }
|
|
26
|
+
if (query.tenant_id) tenant_id = query.tenant_id
|
|
27
|
+
if (params.tenant_id) tenant_id = params.tenant_id
|
|
28
|
+
|
|
29
|
+
return tenant_id
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
// main
|
|
24
33
|
const authenticateUser = async (request, response, next) => {
|
|
25
34
|
try {
|
|
@@ -39,7 +48,7 @@ const authenticateUser = async (request, response, next) => {
|
|
|
39
48
|
|
|
40
49
|
const { tenant_id, is_admin } = await jwt.verify(token, SECRET, { issuer: ISSUER });
|
|
41
50
|
request.is_admin = !!is_admin;
|
|
42
|
-
request.tenant_id = is_admin ?
|
|
51
|
+
request.tenant_id = is_admin ? extract_tenant_id(request) : tenant_id;
|
|
43
52
|
|
|
44
53
|
next();
|
|
45
54
|
} catch (e) {
|