supabase / auth-js

An isomorphic Javascript library for Supabase Auth.
MIT License
370 stars 165 forks source link

Argument of type 'string | undefined' is not assignable to parameter of type 'string' in @supabase/auth-js #967

Open thewhalermelon opened 1 month ago

thewhalermelon commented 1 month ago

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:

  1. Go to 'https://github.com/supabase/auth-js/blob/master/src/lib/helpers.ts'
  2. Click on line 208
  3. See error

Expected behavior

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))
}

Screenshots

image

System information