Skip to content

TypeScript error in decodeJWTPayload blocking CI/CD TypeScript checks #1017

Closed
@ganeshrvel

Description

@ganeshrvel

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

This is a duplicate of #967 which has been open since January 2024 without resolution. The TypeScript error in decodeJWTPayload function in auth-js is blocking our CI/CD pipeline as we cannot run TypeScript checks (tsc --noEmit --skipLibCheck --pretty) or ESLint validation before commits.

To Reproduce

Steps to reproduce:

  1. Install supabase-js v2.45.2
  2. Run TypeScript checks with tsc --noEmit --skipLibCheck --pretty
  3. Observe TypeScript compilation errors due to incorrect typing in decodeJWTPayload

Expected behavior

The decodeJWTPayload function should be properly typed as shown in the original issue #967:

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

This issue is blocking our ability to maintain code quality through TypeScript and ESLint checks in our CI pipeline.

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