Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit bb85f81

Browse files
committed
fix(serve): Disable JWT is environment variable NODE_ENV is 'development'
1 parent 1709529 commit bb85f81

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/serve.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ const jsonParser = require('body-parser').json()
1818
app.use(jsonParser)
1919

2020
const DEFAULT_ENVIRONMENT = 'multi-mega'
21+
const JWT_ENABLED = process.env.NODE_ENV !== 'development'
2122

2223
/**
2324
* Secret for JSON web tokens.
2425
*/
25-
let JWT_SECRET = process.env.JWT_SECRET
26-
if (!JWT_SECRET) {
27-
if (process.env.NODE_ENV === 'development') JWT_SECRET = 'not-a-secret'
28-
else throw Error('JWT_SECRET must be set')
29-
}
26+
if (JWT_ENABLED) {
27+
const JWT_SECRET = process.env.JWT_SECRET
28+
if (!JWT_SECRET) {
29+
throw Error('JWT_SECRET must be set')
30+
}
3031

31-
app.use(jwt({ secret: JWT_SECRET }))
32+
app.use(jwt({ secret: JWT_SECRET }))
33+
}
3234

3335
/**
3436
* Validates that all the `requiredParameters` are properties of `body`.
@@ -100,6 +102,12 @@ function doRequestValidation (request: express.Request, response: express.Respon
100102
* @param expectedContainerId
101103
*/
102104
function getJwtData (request: express.Request, response: express.Response, expectedContainerId: string | null = null): any {
105+
if (!JWT_ENABLED) {
106+
return {
107+
'cid': expectedContainerId
108+
}
109+
}
110+
103111
// @ts-ignore
104112
const jwtData: any = request.user
105113

0 commit comments

Comments
 (0)