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

Remove extra token exchange for B2B #2736

Merged
merged 7 commits into from
Feb 5, 2025
Merged

Conversation

dustinfirman
Copy link
Contributor

@dustinfirman dustinfirman commented Jan 30, 2025

Upgrade instructions

B2B methods and props are now stable. Warnings are in place for unstable usages and will be removed completely in the next major version.

  1. Search for anywhere using UNSTABLE_getBuyer and UNSTABLE_setBuyer is update accordingly.

    - customerAccount.UNSTABLE_getBuyer();
    + customerAccount.getBuyer()
    
    - customerAccount.UNSTABLE_setBuyer({
    + customerAccount.setBuyer({
        companyLocationId,
      });
  2. Update createHydrogenContext to remove the unstableB2b option

      const hydrogenContext = createHydrogenContext({
        env,
        request,
        cache,
        waitUntil,
        session,
        i18n: {language: 'EN', country: 'US'},
    -    customerAccount: {
    -      unstableB2b: true,
    -    },
        cart: {
          queryFragment: CART_QUERY_FRAGMENT,
        },
      });

WHY are these changes introduced?

Fixes https://github.com/Shopify/core-issues/issues/73720

With the initial support of B2B for headless we had to use a non ideal API which included an extra token exchange. Now that buyer auth as moved to core and the GraphQl API supports it, we can remove this extra token exchange and use the customer access token.

WHAT is this pull request doing?

  1. Removes the unstableB2b prop from the customer account client since we no longer need to do the token exchange.
  2. Updates UNSTABLE_getBuyer -> getBuyer and UNSTABLE_setBuyer -> setBuyer. The logic in getBuyer has changed since it will now grab the customerAccountAccess token that is stored in state. From a usage perspective these functions should behave the same as before. I did this so merchants shouldn't need to change any logic other than switching the function name.
  3. Updates the B2B example to reflect the above changes

HOW to test your changes?

I ran this locally for testing.

  1. npm run dev in the hydrogen repo
  2. npm run dev in the B2B example
  3. Started an ngrok tunnel, which you can access here: https://e99a-198-98-107-190.ngrok-free.app
  4. configured my staff store to accept that ngrok tunnel for customer account auth

DM me if you want to test on my store and I can add you as a B2B buyer.

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

Copy link
Contributor

shopify bot commented Jan 30, 2025

Oxygen deployed a preview of your df/update-b2b-token-exchange branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
classic-remix ✅ Successful (Logs) Preview deployment Inspect deployment February 4, 2025 7:24 PM
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment February 4, 2025 7:24 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment February 4, 2025 7:24 PM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment February 4, 2025 7:24 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment February 4, 2025 7:24 PM

Learn more about Hydrogen's GitHub integration.

removed references to unstable for b2b
@dustinfirman dustinfirman force-pushed the df/update-b2b-token-exchange branch from c77fdc6 to f32ccd1 Compare January 30, 2025 16:12
@dustinfirman dustinfirman marked this pull request as ready for review January 30, 2025 16:37
@wizardlyhel wizardlyhel merged commit 3ea2582 into main Feb 5, 2025
12 checks passed
@wizardlyhel wizardlyhel deleted the df/update-b2b-token-exchange branch February 5, 2025 19:39
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 this pull request may close these issues.

2 participants