Skip to content

fix(loyalty): honor configured admin auth type in admin SDK#16164

Merged
NicolasGorga merged 3 commits into
developfrom
dx-2801
Jul 23, 2026
Merged

fix(loyalty): honor configured admin auth type in admin SDK#16164
NicolasGorga merged 3 commits into
developfrom
dx-2801

Conversation

@shahednasser

Copy link
Copy Markdown
Member

Summary

What — The loyalty plugin's admin SDK (packages/plugins/loyalty/src/admin/lib/sdk.ts) was hard-coded to auth: { type: "session" }. This PR makes it read the bundler-injected __BACKEND_URL__, __AUTH_TYPE__, and __JWT_TOKEN_STORAGE_KEY__ globals, mirroring the dashboard's own client config, so the plugin honors the admin's configured auth type.

Why — In any app configured for JWT admin auth (ADMIN_AUTH_TYPE=jwt, as documented), there is no session cookie, so every request the plugin's data hooks make returned 401. Concretely, the Gift Card Products page (GET /admin/products?is_giftcard=true) got a 401 and silently rendered "No gift card products found" even when gift-card products existed. The failure was silent, which cost significant debugging time. As-is, the plugin's admin pages are unusable under JWT admin auth.

How — Replaced the hard-coded config with the same globals the main dashboard uses. These globals are injected as Vite define values by @medusajs/admin-bundler for all bundled admin code (including plugin admin extensions), so no additional wiring is needed. Since src/admin is type-checked under a separate strict tsconfig (the root tsconfig excludes it), a vite-env.d.ts declaring these globals was added. All of the plugin's data hooks import this single shared sdk, so the fix propagates everywhere.

Testing — Type-checked the plugin admin (tsc --noEmit under src/admin/tsconfig.json) with no new errors. To verify end to end: set ADMIN_AUTH_TYPE=jwt, log into the admin, and open Gift Cards → Gift Card Products — the list now loads existing gift-card products instead of returning 401 / rendering empty.


Checklist

  • I have added a changeset for this PR (patch)
  • The changes are covered by relevant tests
  • I have verified the code works as intended locally
  • I have linked the related issue(s) if applicable

Additional Context

Resolves DX-2801. The fix mirrors packages/admin/dashboard/src/lib/client/client.ts.

🤖 Generated with Claude Code

shahednasser and others added 2 commits July 23, 2026 11:27
The loyalty plugin's admin SDK was hard-coded to `auth: { type: "session" }`,
so every request its data hooks make (e.g. the Gift Card Products page's
`GET /admin/products?is_giftcard=true`) returned 401 in any app configured
for JWT admin auth (`ADMIN_AUTH_TYPE=jwt`). The pages silently rendered
empty ("No gift card products found") instead of surfacing the failure.

Mirror the dashboard's client config by reading the bundler-injected
`__BACKEND_URL__`, `__AUTH_TYPE__`, and `__JWT_TOKEN_STORAGE_KEY__` globals
so the plugin respects the admin's configured auth type. Add a declaration
file for these globals since `src/admin` is type-checked under a separate
strict tsconfig.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shahednasser
shahednasser requested a review from a team as a code owner July 23, 2026 08:29
@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5e362da

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 79 packages
Name Type
@medusajs/loyalty-plugin Patch
@medusajs/medusa Patch
@medusajs/test-utils Patch
@medusajs/analytics Patch
@medusajs/api-key Patch
@medusajs/auth Patch
@medusajs/cache-inmemory Patch
@medusajs/cache-redis Patch
@medusajs/caching Patch
@medusajs/cart Patch
@medusajs/currency Patch
@medusajs/customer Patch
@medusajs/event-bus-local Patch
@medusajs/event-bus-redis Patch
@medusajs/file Patch
@medusajs/fulfillment Patch
@medusajs/index Patch
@medusajs/inventory Patch
@medusajs/link-modules Patch
@medusajs/locking Patch
@medusajs/notification Patch
@medusajs/order Patch
@medusajs/payment Patch
@medusajs/pricing Patch
@medusajs/product Patch
@medusajs/promotion Patch
@medusajs/rbac Patch
@medusajs/region Patch
@medusajs/sales-channel Patch
@medusajs/settings Patch
@medusajs/stock-location Patch
@medusajs/store Patch
@medusajs/tax Patch
@medusajs/translation Patch
@medusajs/user Patch
@medusajs/workflow-engine-inmemory Patch
@medusajs/workflow-engine-redis Patch
@medusajs/analytics-local Patch
@medusajs/analytics-posthog Patch
@medusajs/auth-emailpass Patch
@medusajs/auth-github Patch
@medusajs/auth-google Patch
@medusajs/caching-redis Patch
@medusajs/file-local Patch
@medusajs/file-s3 Patch
@medusajs/fulfillment-manual Patch
@medusajs/locking-postgres Patch
@medusajs/locking-redis Patch
@medusajs/notification-local Patch
@medusajs/notification-sendgrid Patch
@medusajs/payment-stripe Patch
@medusajs/draft-order Patch
@medusajs/core-flows Patch
@medusajs/framework Patch
@medusajs/js-sdk Patch
@medusajs/modules-sdk Patch
@medusajs/orchestration Patch
@medusajs/query Patch
@medusajs/types Patch
@medusajs/utils Patch
@medusajs/workflows-sdk Patch
@medusajs/http-types-generator Patch
@medusajs/cli Patch
@medusajs/medusa-oas-cli Patch
@medusajs/oas-github-ci Patch
@medusajs/deps Patch
@medusajs/eslint-plugin Patch
@medusajs/telemetry Patch
@medusajs/admin-bundler Patch
@medusajs/admin-sdk Patch
@medusajs/admin-shared Patch
@medusajs/admin-vite-plugin Patch
@medusajs/dashboard Patch
@medusajs/icons Patch
@medusajs/toolbox Patch
@medusajs/ui-preset Patch
create-medusa-app Patch
integration-tests-http Patch
@medusajs/ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shahednasser
shahednasser requested a review from a team as a code owner July 23, 2026 08:44

@NicolasGorga NicolasGorga left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@NicolasGorga
NicolasGorga merged commit 0731abc into develop Jul 23, 2026
33 checks passed
@NicolasGorga
NicolasGorga deleted the dx-2801 branch July 23, 2026 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants