Skip to content

Commit 3d80039

Browse files
j4w8nkangmingtay
andauthored
fix: assert type in decodeJWTPayload (#1018)
## What kind of change does this PR introduce? Bug fix ## What is the current behavior? Type checking and/or linting does not pass for some configurations, per #967 and #1017 ## What is the new behavior? We're now asserting that `parts[1]` is a string (aka isn't undefined), since we know from a previous check that the array length is 3. ## Additional context Fixes #967 and fixes #1017 Co-authored-by: Kang Ming <[email protected]>
1 parent 510654b commit 3d80039

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: src/lib/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ export function decodeJWTPayload(token: string) {
205205
throw new Error('JWT is not valid: not a JWT structure')
206206
}
207207

208-
if (!base64UrlRegex.test(parts[1])) {
208+
if (!base64UrlRegex.test(parts[1] as string)) {
209209
throw new Error('JWT is not valid: payload is not in base64url format')
210210
}
211211

212-
const base64Url = parts[1]
212+
const base64Url = parts[1] as string
213213
return JSON.parse(decodeBase64URL(base64Url))
214214
}
215215

0 commit comments

Comments
 (0)