@nitra/cf-security 3.3.2 → 3.3.3
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/jwt-c.js +8 -4
package/package.json
CHANGED
package/src/jwt-c.js
CHANGED
|
@@ -8,15 +8,19 @@ import { isDev } from '@nitra/isenv'
|
|
|
8
8
|
* @return {string} token if check passed
|
|
9
9
|
*/
|
|
10
10
|
export default async (req, allowedRoles) => {
|
|
11
|
+
if (!req.raw.headers?.cookie) {
|
|
12
|
+
throw new Error('[verification] missing cookie')
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
// Читаємо кукі
|
|
12
16
|
const c = Object.fromEntries(req.raw.headers.cookie.split('; ').map(v => v.split(/=(.*)/s).map(decodeURIComponent)))
|
|
13
17
|
|
|
14
18
|
// Для дева можна й не передавати токен
|
|
15
19
|
if (isDev) {
|
|
16
20
|
// Але якщо передали - то беремо контент з нього
|
|
17
|
-
if (c
|
|
21
|
+
if (c.__session) {
|
|
18
22
|
// ігноруючи expired
|
|
19
|
-
const token = await verify(c
|
|
23
|
+
const token = await verify(c.__session, { ignoreExpiration: true })
|
|
20
24
|
return token.body
|
|
21
25
|
} else {
|
|
22
26
|
return { name: 'dev', 'https://hasura.io/jwt/claims': { 'x-hasura-allowed-roles': allowedRoles } }
|
|
@@ -24,11 +28,11 @@ export default async (req, allowedRoles) => {
|
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
// Перевіряємо токен тільки
|
|
27
|
-
if (!c
|
|
31
|
+
if (!c.__session) {
|
|
28
32
|
throw new Error('[verification] no authorization header')
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
const token = await verify(c
|
|
35
|
+
const token = await verify(c.__session)
|
|
32
36
|
|
|
33
37
|
if (!token) {
|
|
34
38
|
throw new Error('[verification] invalid token')
|