Skip to content

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

Open
@zlalvani

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.

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