Skip to content

Commit

Permalink
fix: save jwks in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Jan 29, 2025
1 parent bf7c13d commit be6a07a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2608,20 +2608,18 @@ export default class GoTrueClient {
return jwk
}
// jwk isn't cached in memory so we need to fetch it from the well-known endpoint
const {
data: { keys },
error,
} = await _request(this.fetch, 'GET', `${this.url}/.well-known/jwks.json`, {
const { data, error } = await _request(this.fetch, 'GET', `${this.url}/.well-known/jwks.json`, {
headers: this.headers,
})
if (error) {
throw error
}
if (!keys || keys.length === 0) {
if (!data.keys || data.keys.length === 0) {
throw new AuthInvalidJwtError('JWKS is empty')
}
this.jwks = data
// Find the signing key
jwk = keys.find((key: any) => key.kid === kid)
jwk = data.keys.find((key: any) => key.kid === kid)
if (!jwk) {
throw new AuthInvalidJwtError('No matching signing key found in JWKS')
}
Expand Down

0 comments on commit be6a07a

Please sign in to comment.