Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zlalvani opened this issue Feb 24, 2024 · 0 comments · May be fixed by #14
Open

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

zlalvani opened this issue Feb 24, 2024 · 0 comments · May be fixed by #14

Comments

@zlalvani
Copy link

zlalvani commented Feb 24, 2024

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.

@zlalvani zlalvani linked a pull request Feb 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant