Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/embed-sdk/demo-my-invoices.html
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ <h1>My Invoices</h1>
<!-- User menu for authentication -->
<div class="auth-header">
<span>Sign in to continue</span>
<next-user-menu mp-base-url="__MP_BASE_URL__"></next-user-menu>
<next-user-menu mp-base-url="__MP_BASE_URL__" api-host="__API_HOST__"></next-user-menu>
</div>

<!-- The actual widget (hidden until authenticated) -->
Expand Down
2 changes: 1 addition & 1 deletion packages/embed-sdk/demo-profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h1>Profile Editor</h1>
<!-- User menu for authentication -->
<div class="auth-header">
<span>Sign in to continue</span>
<next-user-menu mp-base-url="__MP_BASE_URL__"></next-user-menu>
<next-user-menu mp-base-url="__MP_BASE_URL__" api-host="__API_HOST__"></next-user-menu>
</div>

<!-- The widget (hidden until authenticated) -->
Expand Down
12 changes: 12 additions & 0 deletions packages/embed-sdk/src/shared/base-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ export abstract class MPNextWidget extends HTMLElement {
return new URL(s.src).origin;
} catch { /* continue */ }
}

// Fall back to a sibling widget's api-host (handles Vite dev, where the SDK
// is a local module import — no "next-embed" script tag — and a widget
// without an explicit api-host would otherwise fetch the wrong origin).
const sibling = document.querySelector(
"next-user-menu, next-add-to-calendar, next-full-calendar, next-profile, next-my-invoices",
);
if (sibling && sibling !== this) {
const host = sibling.getAttribute("api-host");
if (host) return host;
}

return "";
}

Expand Down
Loading