Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Jun 6, 2017
Merged
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