The decodeJWTPayload function should be like this:
export function decodeJWTPayload(token: string) {
// Regex checks for base64url format
const base64UrlRegex = /^([a-z0-9_-]{4})*($|[a-z0-9_-]{3}=?$|[a-z0-9_-]{2}(==)?$)$/i
const parts = token.split('.')
if (parts.length !== 3) {
throw new Error('JWT is not valid: not a JWT structure')
}
if (!base64UrlRegex.test(parts[1] as string)) {
throw new Error('JWT is not valid: payload is not in base64url format')
}
const base64Url = parts[1] as string;
return JSON.parse(decodeBase64URL(base64Url))
}
Bug report
Describe the bug
I found the TypeScript error in decodeJWTPayload function in https://github.com/supabase/auth-js/blob/master/src/lib/helpers.ts
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Expected behavior
The decodeJWTPayload function should be like this:
Screenshots
System information