-
-
Notifications
You must be signed in to change notification settings - Fork 571
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
Conversation
…PgTypeIndentifer being provided
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has tripped up a number of people so it's a very welcome addition!
Could you add a test for it so we don't accidentally remove it at a later date whilst refactoring? It would be nice to have tests for all 4 cases: jwtSecret or not ⨉ jwtPgTypeIdentifier or not.
src/postgraphql/postgraphql.ts
Outdated
// 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.\n`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the \n
on the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests would still be welcome
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Apparently I can't merge this on mobile; sorry for delay. |
No problems, I am in no rush :) |
🙏 |
So... It turns out that I am actually using jwtSecret without jwtPgTypeIdentifier - deliberately! I had totally forgotten that. Reason is: I generate the JWT token outside of PostGraphQL, PostGraphQL just uses the jwtSecret to validate the incoming token. I'm going to change this to a warning. |
graphile#466) * fix(postgraphql): Throw an error if jwtSecret is provided without jwtPgTypeIndentifer being provided * Tweaks * Remove semicolon * Adding test
Throws an error if a secret and no token identifier is provided in the options.