Skip to content

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

Closed
@thewhalermelon

Description

@thewhalermelon

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

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

  • OS: macOS
  • Browser: chrome
  • Version of supabase-js: 2.45.2
  • Version of Node.js: 18.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions