@nitra/cf-security 3.2.0 → 3.3.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/package.json +3 -5
- package/src/jwt.js +8 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitra/cf-security",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "check header in cloud functions",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"./jwt": "./src/jwt.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"fix": "npx eslint --fix . && npx prettier --write . ",
|
|
12
11
|
"test": "env $(cat ./test/.env) npx coverage-node test/index.js"
|
|
13
12
|
},
|
|
14
13
|
"repository": {
|
|
@@ -25,8 +24,7 @@
|
|
|
25
24
|
"eslintConfig": {
|
|
26
25
|
"extends": [
|
|
27
26
|
"@nitra/eslint-config/node"
|
|
28
|
-
]
|
|
29
|
-
"root": true
|
|
27
|
+
]
|
|
30
28
|
},
|
|
31
29
|
"devDependencies": {
|
|
32
30
|
"@nitra/eslint-config": "^1.0.9",
|
|
@@ -37,7 +35,7 @@
|
|
|
37
35
|
"@nitra/bunyan": "^1.1.1",
|
|
38
36
|
"@nitra/check-env": "^2.0.1",
|
|
39
37
|
"@nitra/isenv": "^2.0.1",
|
|
40
|
-
"@nitra/jwt": "^3.
|
|
38
|
+
"@nitra/jwt": "^3.3.0"
|
|
41
39
|
},
|
|
42
40
|
"files": [
|
|
43
41
|
"src"
|
package/src/jwt.js
CHANGED
|
@@ -8,8 +8,15 @@ import { isDev } from '@nitra/isenv'
|
|
|
8
8
|
* @return {string} token if check passed
|
|
9
9
|
*/
|
|
10
10
|
export default async (req, allowedRoles) => {
|
|
11
|
+
// Для дева можна й не передавати токен
|
|
11
12
|
if (isDev) {
|
|
12
|
-
|
|
13
|
+
// Але якщо передали - то беремо контент з нього
|
|
14
|
+
if (req.headers?.authorization) {
|
|
15
|
+
// ігноруючи expired
|
|
16
|
+
return verify(req.headers.authorization.split(' ')[1], { ignoreExpiration: true })
|
|
17
|
+
} else {
|
|
18
|
+
return { name: 'dev', 'https://hasura.io/jwt/claims': { 'x-hasura-allowed-roles': allowedRoles } }
|
|
19
|
+
}
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
// Перевіряємо токен тільки
|