Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/authToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ const validateAuthToken = async (
suppressAlert?: boolean,
): Promise<boolean> => {
const cachedAuthToken = getCacheAuthToken();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this line below the type check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// even if token verification is disabled, we will still validate
// that the token is a string before proceeding.
if (typeof authToken !== 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write a unit test for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

const errorMessage = `${ERROR_MESSAGE.INVALID_TOKEN_TYPE_ERROR} ${typeof authToken}.`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use template strings for this

logger.error(errorMessage);
throw new Error(errorMessage);
}

if (embedConfig.disableTokenVerification) {
logger.info('Token verification is disabled. Assuming token is valid.');
return true;
Expand Down
1 change: 1 addition & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const ERROR_MESSAGE = {
SDK_NOT_INITIALIZED: 'SDK not initialized',
SESSION_INFO_FAILED: 'Failed to get session information',
INVALID_TOKEN_ERROR: 'Received invalid token from getAuthToken callback or authToken endpoint.',
INVALID_TOKEN_TYPE_ERROR: 'Expected getAuthToken to return a string, but received a ',
MIXPANEL_TOKEN_NOT_FOUND: 'Mixpanel token not found in session info',
PRERENDER_ID_MISSING: 'PreRender ID is required for preRender',
SYNC_STYLE_CALLED_BEFORE_RENDER: 'PreRender should be called before using syncPreRenderStyle',
Expand Down
Loading