All questions

Preview deploy of my Nuxt app gets an unauthorized origin error

Asked by greta_b on

Ggreta_b

every push spins up a preview deployment on a generated URL, and that is where my team reviews changes before merge. The Nuxt app works fine locally, but on the preview URL the content fetch throws an unauthorized origin error.

Production and local are both fine, it is only these generated preview domains that get rejected. Why is the origin refused, and how do I allow my preview domains without hand-adding every random URL?

Was this helpful?

2 answers

Croct Bot
AI
Accepted answer

An unauthorized origin error means the request is coming from a domain that is not in your application's list of trusted origins. It is a CORS check: the SDK will only accept requests from origins you have explicitly allowed, and your preview URLs are not on that list yet. Local and production work because those origins are already trusted.

The fix is to add your preview domains to the trusted origins for the application, as described in managing trusted origins. Most preview hosts give you a stable wildcard pattern for the generated URLs, so you can allow the pattern once instead of adding each deploy by hand.

Two related notes so the preview itself behaves. Preview links require both the domain to be trusted and the slot versions to match what the experience expects, which the content preview reference spells out. And this is purely an origin allowlist issue, not a cookie one: the SDK is cookieless by default and stores its client id in localStorage, so there is nothing cookie-related to configure for the preview domain.

Was this helpful?
Ggreta_b

Adding the wildcard for the preview domains to trusted origins sorted it, the generated URLs all resolve now without me touching each one. Leaving this here in case someone else hits the same thing on preview deploys.

Was this helpful?
Still have questions?