Skip to content
This repository was archived by the owner on Nov 12, 2026. It is now read-only.
This repository was archived by the owner on Nov 12, 2026. It is now read-only.

Underscores in keyPrefix cause extractShortToken to return the wrong segment #13

Open

Description

@zlalvani

For example,

const { token } = await generateAPIKey({
  keyPrefix: "mycompany_token",
});

const shortToken = extractShortToken(token); // resolves to 'token'

This is caused by the implementation splitting the token on _ and always fetching the second element:

export const extractShortToken = (token: string) => token.split("_")?.[1]

One possible solution would be to adjust the logic to index backwards from the end:

export const extractShortToken = (token: string) => token.split("_").reverse()?.[1]

There could be a way to use template literal types to prevent the usage of _ in the prefix, but that would be challenging to implement if it was even possible.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions