diff --git a/packages/api/src/platforms/vtex/resolvers/validateSession.ts b/packages/api/src/platforms/vtex/resolvers/validateSession.ts index 661df7e385..1a624d2634 100644 --- a/packages/api/src/platforms/vtex/resolvers/validateSession.ts +++ b/packages/api/src/platforms/vtex/resolvers/validateSession.ts @@ -123,9 +123,9 @@ export const validateSession = async ( seller: seller?.id, hasOnlyDefaultSalesChannel: !store?.channel?.value, }), - b2b: { - customerId: authentication?.customerId?.value ?? '', - }, + b2b: authentication?.customerId?.value + ? { customerId: authentication.customerId.value } + : null, marketingData, person: profile?.id ? { diff --git a/packages/core/src/sdk/session/index.ts b/packages/core/src/sdk/session/index.ts index d074f25998..4b43597e8b 100644 --- a/packages/core/src/sdk/session/index.ts +++ b/packages/core/src/sdk/session/index.ts @@ -62,11 +62,10 @@ export const mutation = gql(` export const validateSession = async (session: Session) => { // If deliveryPromise is enabled and there is no postalCode in the session if (storeConfig.deliveryPromise?.enabled && !session.postalCode) { - const isLoggedIn = !!session.person?.id + const userId = session.b2b?.customerId ?? session.person?.id - // If user is logged try to get the location (postalCode / geoCoordinates / country) from the user's address - if (isLoggedIn) { - const userId = session.person?.id + // If user is logged in try to get the location (postalCode, geoCoordinates and country) from the user's address + if (userId) { const address = await getSavedAddress(userId) // Save the location in the session