Skip to content

Commit

Permalink
fix(postgraphql): Throw if jwtSecret set but jwtPgTypeIndentifer isn't (
Browse files Browse the repository at this point in the history
#466)

* fix(postgraphql): Throw an error if jwtSecret is provided without jwtPgTypeIndentifer being provided

* Tweaks

* Remove semicolon

* Adding test
  • Loading branch information
mikeburgh authored and benjie committed Jun 6, 2017
1 parent bf2c857 commit f68056c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/postgraphql/__tests__/postgraphql-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,8 @@ test('will create a new PostGraphQL schema on when `watchPgSchemas` emits a chan
])
console.log = origLog
})

test('will error if jwtSecret is provided without jwtPgTypeIdentifier', async () => {
const pgPool = new Pool()
expect(() => postgraphql(pgPool, [], { jwtSecret: 'test' })).toThrow()
})
6 changes: 6 additions & 0 deletions src/postgraphql/postgraphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ export default function postgraphql (
options = schemaOrOptions
}

// Check for a jwtSecret without a jwtPgTypeIdentifier
// a secret without a token identifier prevents JWT creation
if (options.jwtSecret && !options.jwtPgTypeIdentifier) {
throw new Error('jwtSecret provided, however jwtPgTypeIdentifier (token identifier) not provided.')
}

// Creates the Postgres schemas array.
const pgSchemas: Array<string> = Array.isArray(schema) ? schema : [schema]

Expand Down

0 comments on commit f68056c

Please sign in to comment.