Skip to content

Commit

Permalink
[JWT] allow getToken to return a promise (#3029)
Browse files Browse the repository at this point in the history
* [JWT] allow getToken to return a promise

* changeset
  • Loading branch information
EmrysMyrddin authored Sep 28, 2023
1 parent 2a12236 commit 2d0cd18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/wise-goats-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-yoga/plugin-jwt': minor
---

Allow getToken to return a promise.
4 changes: 2 additions & 2 deletions packages/plugins/jwt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface JwtPluginOptionsBase {
request: Request;
serverContext: object | undefined;
url: URL;
}) => string | undefined;
}) => Promise<string | undefined> | string | undefined;
}

export interface JwtPluginOptionsWithJWKS extends JwtPluginOptionsBase {
Expand Down Expand Up @@ -81,7 +81,7 @@ export function useJWT(options: JwtPluginOptions): Plugin {

return {
async onRequest({ request, serverContext, url }) {
const token = getToken({ request, serverContext, url });
const token = await getToken({ request, serverContext, url });
if (token != null) {
const signingKey = options.signingKey ?? (await fetchKey(jwksClient, token));

Expand Down

0 comments on commit 2d0cd18

Please sign in to comment.