Skip to content

fix(api): identify B2B sessions by organizational unit and contract - #3559

Merged
eduardoformiga merged 4 commits into
devfrom
cursor/b2b-session-by-unit
Oct 28, 2026
Merged

eduardoformiga merged 4 commits into
devfrom
cursor/b2b-session-by-unit

Conversation

@eduardoformiga

@eduardoformiga eduardoformiga commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

What's the purpose of this pull request?

FastStore decides whether a shopper is a B2B buyer from the isRepresentative claim in the VTEX ID token. That flag is not the rule Buyer Portal uses: it identifies a B2B buyer by the organizational unit (unitId) plus a contract (customerId). The flag can be true outside B2B, and an earlier token refresh path dropped it (and the unitId), turning B2B buyers into B2C ones.

Because session.b2b was null whenever the flag was off, every client fix that depends on it (PLP refetch, contract switching, refresh token, Quotes and Cards in My Account) silently skipped buyers who have a unit and a contract but no flag.

How it works?

  • buildB2bSession (@faststore/api): returns b2b only when there is a unit and a contract. The unit comes from the session authentication namespace or the JWT; the contract from the session's active contract, then authentication.customerId, then the JWT. Blank values fall through. The isRepresentative argument is gone; the field in the returned object stays true, so existing consumers that read it as "B2B member" keep working.
  • validateSession: the contract lookup is gated on the unit instead of the flag.
  • accountProfile: follows the same rule. It returns the contract information when the token has a unit and a contract is found (session active contract, authentication.customerId, then the JWT), regardless of the flag. A unit without a contract, or a token without a unit (even if flagged as representative), gets the user profile.
  • Claims and session values that are not strings are treated as missing instead of throwing.
  • getIsB2BBuyer (@faststore/core, formerly getIsRepresentative): true when the token carries a non-blank unitId and customerId. It gates the organization drawer and the B2B pages in My Account. The isRepresentative props in the account and navigation components are renamed to isB2BBuyer, and the navigation reads session.b2b presence instead of b2b.isRepresentative.
  • The isRepresentative claim is no longer read by FastStore. resolveJwtClaims stops returning it.

Deprecations (no breaking change)

  • StoreB2B.isRepresentative (GraphQL) is marked @deprecated. It is still returned as true whenever b2b is set; check that b2b is not null instead.
  • B2bInfo.isRepresentative (@faststore/sdk) is marked @deprecated with the same meaning.
  • OrganizationSignInButton_unstable accepts the new isB2BBuyer prop and keeps isRepresentative as a deprecated alias.

Removal of these is left for the next major.

Security review

This changes how a session is classified as B2B, which decides who sees the contract-level account data: a unit member with a contract now gets it even without the isRepresentative flag, and a flagged token without a unit no longer does. The rule matches Buyer Portal and the order authorization, which already moved from isRepresentative to the unit. Change to the B2B session identification rule approved by @eduardoformiga.

How to test it?

  • Log in with a Buyer Portal buyer that has a unit and a contract: session.b2b is filled, the organization drawer and My Account B2B pages show up.
  • Log in with a regular shopper: session.b2b is null and My Account shows the B2C menu.
  • Unit tests: cd packages/api && pnpm test:unit and cd packages/core && pnpm vitest run --project node test/sdk/account/getIsB2BBuyer.test.ts plus the account and navigation browser tests.

Starters Deploy Preview

Use the CodeSandbox build generated for this PR.

References

Checklist

  • PR title and commit messages follow the Conventional Commits specification
  • Added a label according to the PR goal
  • No dependency changes
  • PR description
Open in Web Open in Cursor 

Build session.b2b, accountProfile and the My Account B2B gate from the unitId and the contract instead of the isRepresentative claim, which can be true outside B2B and was dropped by an earlier token refresh path.
@eduardoformiga
eduardoformiga requested a review from a team as a code owner October 28, 2026 20:36
@eduardoformiga
eduardoformiga requested review from hellofanny and lemagnetic and removed request for a team October 28, 2026 20:36

if (jwt?.isRepresentative) {
if (jwt?.unitId?.trim()) {
const sessionData = await commerce.session('').catch(() => null)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Evolvability.Organizational] 🟡 RESTRICT

The 'is this shopper a B2B representative' check is now implemented three different ways in this PR: query.ts only requires a non-blank jwt.unitId; validateSessionHelpers.buildB2bSession (via resolveB2bUnitId/firstNonBlank) requires both a unit AND a resolved customerId/contract; and packages/core/getIsRepresentative requires both jwt.unitId AND jwt.customerId. query.ts never calls the new resolveB2bUnitId helper and doesn't check customerId at all, so a shopper with a unitId but no contract could be routed into the B2B branch of accountProfile while packages/core's getIsRepresentative (used for UI gating) would classify the same shopper as non-representative.

Action: Reuse resolveB2bUnitId (and an equivalent contract/customerId check) in query.ts instead of inlining jwt?.unitId?.trim(), so the three call sites agree on what makes a shopper 'B2B'.

To dismiss: reply /dk-review dismiss [reason] under this comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ab97c85. accountProfile now uses resolveB2bUnitId and resolves the contract with the same chain as buildB2bSession (session active contract, authentication.customerId, then the JWT). A unit without a contract falls back to the user profile, so the resolver, buildB2bSession and getIsB2BBuyer agree on what a B2B buyer is.


if (jwt?.isRepresentative) {
if (jwt?.unitId?.trim()) {
const sessionData = await commerce.session('').catch(() => null)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Check] 🟡 RESTRICT

jwt?.unitId?.trim() calls .trim() directly on the JWT claim without verifying it is a string first. The sibling change in packages/core/src/sdk/account/getIsRepresentative.ts explicitly guards with isNonBlankString (typeof check) precisely because JWT claim shapes aren't guaranteed — and a dedicated test ('with non-string claims') was added there to cover it. query.ts has no equivalent guard and no equivalent test, so a non-string unitId claim would throw inside the resolver.

Action: Use the same type-safe check (e.g. the new resolveB2bUnitId helper, or an isNonBlankString-style guard) here instead of calling .trim() on an untyped claim.

To dismiss: reply /dk-review dismiss [reason] under this comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ab97c85. The resolver no longer calls .trim() on the claim: it goes through resolveB2bUnitId/firstNonBlank, which skip non-string values. Covered by the new "treats non-string unit and contract claims as missing" test in query.test.ts.

describe('buildB2bSession', () => {
it('returns null when the shopper is not a representative', () => {
const emptyArgs = {
authentication: null,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Support] 🟡 RESTRICT

These tests pin down a behavioral change to how B2B representative sessions are derived: buildB2bSession no longer accepts an isRepresentative flag and instead infers representative status purely from the presence of a unit + resolved contract, and getIsRepresentative/Query.accountProfile now ignore the JWT's isRepresentative claim entirely. This is a change to session/authentication-adjacent logic that decides which identity (shopper vs. representative) a request resolves to. AGENTS.md's Security & Data Handling section requires that modifications to authentication mechanisms get explicit human approval recorded in the PR description — nothing in the provided diff/PR context shows that approval was recorded.

Action: Confirm this change was reviewed as an authentication/session-resolution change and record explicit approval in the PR description, per AGENTS.md.
Source: AGENTS.md#security--data-handling

To dismiss: reply /dk-review dismiss [reason] under this comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Addressed. The PR description now has a "Security review" section describing the authorization impact (who gets the contract-level account data) and recording the approval of the new B2B session rule by @eduardoformiga.

@dk-pr-review

dk-pr-review Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

DK Review — Audit Summary

Verdict: ⚠️ RESTRICTED

Severity Count
BLOCK 0
RESTRICT 4
SUGGEST 4

Only BLOCK and RESTRICT findings anchored to a changed line are commented inline on the diff. The other 4 findings below open no review thread.

Scenarios evaluated: feature-flags, general-review, quality-ratchet
Scenarios skipped: dependency-governance (no matching files), pipeline-config (no matching files), agent-skills-review (no matching files)

⚠️ Governance warnings: Large PR detected (40 files) — review coverage may be incomplete


📋 Findings (8)

RESTRICT

  1. [Functional.Logic] packages/api/src/platforms/vtex/resolvers/validateSession.ts:215 — validateSession fetches the B2B contract keyed only by profile.id.value (if (resolveB2bUnitId(authentication, unitId) && profile?.id?.value) { contract = await getContractById({ contractId: profile.id.value }) }), but buildB2bSession now resolves the returned customerId field with a different priority chain that puts shopper.activeContractId.value first (validateSessionHelpers.ts: firstNonBlank(args.shopper?.activeContractId?.value, args.authentication?.customerId?.value, args.customerId)). resolveActiveContractIdFromSession in utils/contract.ts documents these three session fields (shopper.activeContractId, authentication.customerId, profile.id) as independent values that can disagree — it exists precisely as a fallback chain for the availableContracts resolver. No code in this repo writes shopper.activeContractId; it is set externally by VTEX Session Manager/buyer-portal when a shopper switches their active contract, so there is no guarantee profile.id.value is refreshed in lockstep. When they diverge, buildB2bSession returns a b2b.customerId for the newly active contract while b2b.contractName (derived from the contract fetched via the stale profile.id.value) still reflects the previous contract — surfacing a contract id and organization name that belong to two different contracts.
    → Fetch the contract (and gate the fetch) using the same contractId priority chain used for customerId in buildB2bSession (shopper.activeContractId → authentication.customerId → jwt customerId), e.g. reuse resolveActiveContractIdFromSession/firstNonBlank for the getContractById call in validateSession.ts instead of hardcoding profile.id.value.
  2. [Functional.Logic] packages/api/src/platforms/vtex/resolvers/query.ts:893 — accountProfile's B2B gate resolveB2bUnitId(null, jwt.unitId) only ever consults the JWT's unitId claim (authentication is hard-coded to null), while validateSession.ts/buildB2bSession prefer the live session's authentication.unitId and only fall back to the JWT claim. Since this PR ships an organizational-unit switcher (OrganizationDrawer 'switch' view) that updates the session without reissuing the JWT, a shopper whose unit changes mid-session (or who never had a unit in the original JWT) can have accountProfile silently fall through to the b2c branch even though session.b2b reports them as a B2B buyer elsewhere in the app.
    → Fetch the session first (or restructure the resolver) so the gate can use resolveB2bUnitId(authentication, jwt.unitId) the same way validateSession.ts does, keeping the two resolvers' B2B determination consistent.
  3. [agents-md.auth-approval-required] packages/api/src/platforms/vtex/resolvers/validateSession.ts:215 — This PR changes how B2B/representative status is derived from the VTEX ID JWT and session authentication claims (resolveJwtClaims, resolveB2bUnitId, buildB2bSession), and that derivation now also gates page-level authorization (e.g. user-details.tsx redirects unauthenticated-for-B2B users). The repository's AGENTS.md states: 'Modifications to authentication, CSRF, or CSP mechanisms require explicit human approval recorded in the PR description.' Please confirm this approval is recorded.
    → Add a note in the PR description documenting the human review/approval of this authentication-claim behavior change, per AGENTS.md's Security & Data Handling policy.
    Source: AGENTS.md#security--data-handling
  4. [Functional.Security] packages/api/test/unit/platforms/vtex/utils/validateSessionHelpers.test.ts:141 — The diff removes the isRepresentative flag entirely from B2B session/JWT-claim resolution (buildB2bSession, resolveJwtClaims, Query.accountProfile) and replaces it with implicit B2B-buyer detection based on presence of a unit + contract claim. This changes how authorization-relevant session state is derived from the JWT, which falls under 'Modifications to authentication ... mechanisms require explicit human approval recorded in the PR description' per AGENTS.md Security & Data Handling.
    → Confirm the PR description explicitly documents and records human approval for this change to JWT/session-based B2B authorization logic before merging.

SUGGEST

  1. [Functional.Check] packages/api/src/platforms/vtex/resolvers/validateSession.ts — No test was added/updated for validateSession.ts covering the new activeContractId-aware buildB2bSession behavior in combination with the resolver's own contract-fetch gate (which still keys off profile.id.value only). The existing unit tests for buildB2bSession (validateSessionHelpers.test.ts) exercise the function in isolation with hand-picked contract/profile args, so they can't catch the resolver wiring a mismatched contractId into getContractById.
    → Add a validateSession.ts test where shopper.activeContractId differs from profile.id.value and assert the returned b2b.customerId and b2b.contractName refer to the same contract.
  2. [Evolvability.Organizational] packages/core/src/sdk/account/getIsB2BBuyer.ts:23 — The B2B-buyer business rule ('non-blank unitId AND non-blank customerId from the JWT') is now implemented twice: as resolveB2bUnitId/firstNonBlank in packages/api/.../validateSessionHelpers.ts and independently as isNonBlankString checks here in packages/core. The two implementations can drift (e.g. if blank-handling or the definition of 'B2B' changes in one package but not the other), producing inconsistent B2B detection between the API session resolvers and the core SSR gates.
    → Extract the shared predicate into a small reusable utility (or at least cross-reference the two implementations in a comment) so future changes to the B2B definition are made in one place.
  3. [agents-md.generated-file-edit] packages/api/src/__generated__/schema.ts:1363 — Changes land directly inside __generated__/schema.ts and @generated/graphql.ts (and the matching isRepresentative deprecation note in packages/sdk/src/session/index.ts). AGENTS.md forbids editing @generated//__generated__/ directories directly without explicit human approval; this is presumably just codegen output from the session.graphql deprecation directive, but please confirm it was produced by running the generator (not hand-edited) so it can't drift from the schema source of truth.
    → Confirm these generated files were produced by pnpm generate/codegen after editing session.graphql, not hand-edited, and note that in the PR description.
    Source: AGENTS.md#agent-autonomy-boundaries
  4. [Evolvability.SupportedByLanguage] packages/api/test/unit/platforms/vtex/utils/validateSessionHelpers.test.ts:184 — The test is forced to use as unknown as string casts to pass non-string values (42, an object) into buildB2bSession's unitId/customerId parameters, indicating the function's TypeScript signature claims plain string for values that actually originate from untrusted/decoded JWT claims and can be any JSON type at runtime. The equivalent helper in query.test.ts already types its claims as Record<string, unknown>, showing the inconsistency.
    → Type unitId/customerId (and related JWT claim fields) as unknown and validate with a runtime type guard inside buildB2bSession/resolveJwtClaims, instead of declaring string and relying on test-only unsafe casts to exercise the non-string branch.

DK Review v1.0.0 | To dismiss a finding: reply /dk-review dismiss [reason] under its comment

Rename getIsRepresentative to getIsB2BBuyer and the isRepresentative props to isB2BBuyer, read session.b2b presence in the navigation, and stop reading the isRepresentative JWT claim in the API. StoreB2B.isRepresentative, B2bInfo.isRepresentative and the OrganizationSignInButton prop stay as deprecated aliases.
@pkg-pr-new

pkg-pr-new Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

npm i https://pkg.pr.new/vtex/faststore/@faststore/api@ab97c85

@faststore/cli

npm i https://pkg.pr.new/vtex/faststore/@faststore/cli@ab97c85

@faststore/components

npm i https://pkg.pr.new/vtex/faststore/@faststore/components@ab97c85

@faststore/core

npm i https://pkg.pr.new/vtex/faststore/@faststore/core@ab97c85

@faststore/diagnostics

npm i https://pkg.pr.new/vtex/faststore/@faststore/diagnostics@ab97c85

@faststore/lighthouse

npm i https://pkg.pr.new/vtex/faststore/@faststore/lighthouse@ab97c85

@faststore/sdk

npm i https://pkg.pr.new/vtex/faststore/@faststore/sdk@ab97c85

@faststore/ui

npm i https://pkg.pr.new/vtex/faststore/@faststore/ui@ab97c85

commit: ab97c85


if (jwt?.isRepresentative) {
if (jwt?.unitId?.trim()) {
const sessionData = await commerce.session('').catch(() => null)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Check] 🟡 RESTRICT

The new gate jwt?.unitId?.trim() calls .trim() without first verifying unitId is a string. If the decoded JWT claim is present but not a string (malformed/legacy token), this throws a TypeError and crashes the accountProfile resolver. The same PR adds a type-safe isNonBlankString guard in getIsB2BBuyer.ts (and even tests it against non-string claims), but that guard isn't reused here.

Action: Reuse a shared isNonBlankString-style guard (check typeof unitId === 'string') before calling .trim(), consistent with getIsB2BBuyer.

To dismiss: reply /dk-review dismiss [reason] under this comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ab97c85, same change as the thread above: the gate uses resolveB2bUnitId, which only accepts non-blank strings, with a test for non-string claims.

}

function firstNonBlank(...values: Array<string | null | undefined>): string {
for (const value of values) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Check] 🟡 RESTRICT

firstNonBlank (used by resolveB2bUnitId and the new buildB2bSession customerId resolution chain) calls value?.trim() without checking typeof value === 'string'. The parameters come from JWT claims and session/authentication namespace values that are only nominally typed as strings; if the actual runtime value is non-string (e.g. a malformed token or unexpected session payload shape), this throws instead of degrading gracefully, unlike the isNonBlankString helper added elsewhere in this same PR.

Action: Add a typeof value === 'string' check inside firstNonBlank before calling .trim().

To dismiss: reply /dk-review dismiss [reason] under this comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ab97c85. firstNonBlank now takes unknown values and checks typeof value === "string" before trimming. Covered by "returns null when the claims are not strings" in validateSessionHelpers.test.ts.


if (jwt?.isRepresentative) {
if (jwt?.unitId?.trim()) {
const sessionData = await commerce.session('').catch(() => null)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Logic] 🟡 RESTRICT

accountProfile now treats a shopper as B2B solely based on jwt?.unitId?.trim(), while the two other B2B-detection implementations introduced in this same PR (getIsB2BBuyer in core, and resolveB2bUnitId/buildB2bSession in the API) both require a non-blank unitId AND a non-blank customerId/contract before treating the session as B2B. If a JWT can ever carry a unitId without a customerId, this resolver will take the B2B/contract branch while the rest of the app (navbar, account layout, page gating) would not consider the user a B2B buyer, producing inconsistent behavior across the product.

Action: Reuse the same unit+customerId check (e.g. via resolveB2bUnitId plus a customerId check, or a shared helper) in accountProfile instead of a standalone unitId check.

To dismiss: reply /dk-review dismiss [reason] under this comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in ab97c85. accountProfile now requires both the unit and a resolved contract before taking the B2B branch, consistent with buildB2bSession and getIsB2BBuyer. Tests cover a unit without a contract (user profile) and a contract coming only from the session.

@sonar-workflows

Copy link
Copy Markdown

@eduardoformiga
eduardoformiga merged commit 0ee7b9a into dev Oct 28, 2026
14 of 16 checks passed
@eduardoformiga
eduardoformiga deleted the cursor/b2b-session-by-unit branch October 28, 2026 23:16
let contract = null
if (isRepresentative && profile?.id?.value) {
if (resolveB2bUnitId(authentication, unitId) && profile?.id?.value) {
try {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Logic] 🟡 RESTRICT

validateSession fetches the B2B contract keyed only by profile.id.value (if (resolveB2bUnitId(authentication, unitId) && profile?.id?.value) { contract = await getContractById({ contractId: profile.id.value }) }), but buildB2bSession now resolves the returned customerId field with a different priority chain that puts shopper.activeContractId.value first (validateSessionHelpers.ts: firstNonBlank(args.shopper?.activeContractId?.value, args.authentication?.customerId?.value, args.customerId)). resolveActiveContractIdFromSession in utils/contract.ts documents these three session fields (shopper.activeContractId, authentication.customerId, profile.id) as independent values that can disagree — it exists precisely as a fallback chain for the availableContracts resolver. No code in this repo writes shopper.activeContractId; it is set externally by VTEX Session Manager/buyer-portal when a shopper switches their active contract, so there is no guarantee profile.id.value is refreshed in lockstep. When they diverge, buildB2bSession returns a b2b.customerId for the newly active contract while b2b.contractName (derived from the contract fetched via the stale profile.id.value) still reflects the previous contract — surfacing a contract id and organization name that belong to two different contracts.

Action: Fetch the contract (and gate the fetch) using the same contractId priority chain used for customerId in buildB2bSession (shopper.activeContractId → authentication.customerId → jwt customerId), e.g. reuse resolveActiveContractIdFromSession/firstNonBlank for the getContractById call in validateSession.ts instead of hardcoding profile.id.value.

To dismiss: reply /dk-review dismiss [reason] under this comment


if (jwt?.isRepresentative) {
if (resolveB2bUnitId(null, jwt.unitId)) {
const sessionData = await commerce.session('').catch(() => null)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Logic] 🟡 RESTRICT

accountProfile's B2B gate resolveB2bUnitId(null, jwt.unitId) only ever consults the JWT's unitId claim (authentication is hard-coded to null), while validateSession.ts/buildB2bSession prefer the live session's authentication.unitId and only fall back to the JWT claim. Since this PR ships an organizational-unit switcher (OrganizationDrawer 'switch' view) that updates the session without reissuing the JWT, a shopper whose unit changes mid-session (or who never had a unit in the original JWT) can have accountProfile silently fall through to the b2c branch even though session.b2b reports them as a B2B buyer elsewhere in the app.

Action: Fetch the session first (or restructure the resolver) so the gate can use resolveB2bUnitId(authentication, jwt.unitId) the same way validateSession.ts does, keeping the two resolvers' B2B determination consistent.

To dismiss: reply /dk-review dismiss [reason] under this comment

let contract = null
if (isRepresentative && profile?.id?.value) {
if (resolveB2bUnitId(authentication, unitId) && profile?.id?.value) {
try {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[agents-md.auth-approval-required] 🟡 RESTRICT

This PR changes how B2B/representative status is derived from the VTEX ID JWT and session authentication claims (resolveJwtClaims, resolveB2bUnitId, buildB2bSession), and that derivation now also gates page-level authorization (e.g. user-details.tsx redirects unauthenticated-for-B2B users). The repository's AGENTS.md states: 'Modifications to authentication, CSRF, or CSP mechanisms require explicit human approval recorded in the PR description.' Please confirm this approval is recorded.

Action: Add a note in the PR description documenting the human review/approval of this authentication-claim behavior change, per AGENTS.md's Security & Data Handling policy.
Source: AGENTS.md#security--data-handling

To dismiss: reply /dk-review dismiss [reason] under this comment

describe('buildB2bSession', () => {
it('returns null when the shopper is not a representative', () => {
const emptyArgs = {
authentication: null,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[Functional.Security] 🟡 RESTRICT

The diff removes the isRepresentative flag entirely from B2B session/JWT-claim resolution (buildB2bSession, resolveJwtClaims, Query.accountProfile) and replaces it with implicit B2B-buyer detection based on presence of a unit + contract claim. This changes how authorization-relevant session state is derived from the JWT, which falls under 'Modifications to authentication ... mechanisms require explicit human approval recorded in the PR description' per AGENTS.md Security & Data Handling.

Action: Confirm the PR description explicitly documents and records human approval for this change to JWT/session-based B2B authorization logic before merging.

To dismiss: reply /dk-review dismiss [reason] under this comment

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.

1 participant