Skip to content

Commit

Permalink
MI-121: Updates the "generateMeshToken" function to return a "custome…
Browse files Browse the repository at this point in the history
…r_id" property instead of "bc_customer_id".

Updates the "getBcCustomerIdFromMeshToken" function to look for a "customer_id" property instead of "bc_customer_id".
  • Loading branch information
brettcutt-aligent committed Nov 21, 2024
1 parent 3b915a4 commit 2a99d81
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 14 additions & 0 deletions packages/modules/bigcommerce/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# BigCommerce GraphQl Module Release Notes

## bigcommerce-graphql-module-1.0.8

#### Changes:

- Updates the "generateMeshToken" function to return a "customer_id" property instead of "bc_customer_id".
Updates the "getBcCustomerIdFromMeshToken" function to look for a "customer_id" property instead of "bc_customer_id".
This is due to the Auth Module generating a JWT containing a "customer_id" property
but the BigCommerce Module decodes the JWT and looks for a "bc_customer_id" property.

#### Tickets

- MI-121: Auth module authentication issue
- https://aligent.atlassian.net/browse/MI-121

## bigcommerce-graphql-module-1.0.6

#### Changes:
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/bigcommerce/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export interface DecodedCustomerImpersonationToken {
}

export interface MeshToken {
bc_customer_id: number;
customer_id: number;
iat: number;
exp: number;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/modules/bigcommerce/src/utils/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export const getDecodedCustomerImpersonationToken = (
};

/**
* Attempts to extract "bc_customer_id" for the mesh token or throws an error
* Attempts to extract "customer_id" for the mesh token or throws an error
* @param meshToken
*/
export const getBcCustomerIdFromMeshToken = (meshToken: string): number => {
try {
if (meshToken?.toLowerCase().startsWith('bearer')) {
const splitMeshToken = meshToken.split(' ')[1];
const decodedMeshToken = verify(splitMeshToken, JWT_PRIVATE_KEY) as MeshToken;
return decodedMeshToken.bc_customer_id;
return decodedMeshToken.customer_id;
} else {
throw new Error(`Need to send Bearer token`);
}
Expand All @@ -48,13 +48,13 @@ export const getBcCustomerIdFromMeshToken = (meshToken: string): number => {
};

/**
* Creates a token when a user logs in also stores the bc_customer_id in the payload
* Creates a token when a user logs in also stores the customer_id in the payload
* which can be used for later request to the Mesh.
* @param {number} entityId - Bc User Id returned from logging in
*/
export const generateMeshToken = (entityId: number): string => {
const payload = {
bc_customer_id: entityId,
customer_id: entityId,
exp: getUnixTimeStampInSecondsForMidnightTonight(),
};

Expand Down

0 comments on commit 2a99d81

Please sign in to comment.