@prismicio/next 2.3.1-pr.148.cfcff00 → 2.3.1-pr.148.d5dbc1a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_previewCookieAttributes = require("./lib/previewCookieAttributes.cjs");
2
3
  let _prismicio_client = require("@prismicio/client");
3
4
  //#region src/exitPreview.ts
4
5
  /**
@@ -17,17 +18,18 @@ let _prismicio_client = require("@prismicio/client");
17
18
  * ```
18
19
  */
19
20
  async function exitPreview() {
20
- const { cookies } = await import("next/headers.js");
21
+ const { cookies, draftMode, headers } = await import("next/headers.js");
22
+ (await draftMode()).disable();
21
23
  const cookieJar = await cookies();
24
+ const cookieAttributes = require_previewCookieAttributes.previewCookieAttributes((await headers()).get("host"));
22
25
  cookieJar.delete({
23
26
  name: "__prerender_bypass",
24
- sameSite: "none",
25
- secure: true
27
+ httpOnly: true,
28
+ ...cookieAttributes
26
29
  });
27
30
  cookieJar.delete({
28
31
  name: _prismicio_client.cookie.preview,
29
- sameSite: "none",
30
- secure: true
32
+ ...cookieAttributes
31
33
  });
32
34
  return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
33
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.cjs","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies } = await import(\"next/headers\")\n\n\t// Expire both cookies with the attributes `redirectToPreviewURL` used.\n\t// `draftMode().disable()` only expires the Draft Mode cookie, and with\n\t// `SameSite=Lax` in development, which a cross-site iframe cannot clear.\n\tconst cookieJar = await cookies()\n\tcookieJar.delete({ name: \"__prerender_bypass\", sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: prismicCookie.preview, sameSite: \"none\", secure: true })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,YAAY,MAAM,OAAO;CAKjC,MAAM,YAAY,MAAM,SAAS;AACjC,WAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAChF,WAAU,OAAO;EAAE,MAAMA,kBAAAA,OAAc;EAAS,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGjF,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
1
+ {"version":3,"file":"exitPreview.cjs","names":["previewCookieAttributes","prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nimport { previewCookieAttributes } from \"./lib/previewCookieAttributes\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode, headers } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// Clear the cookies `redirectToPreviewURL` wrote with the attributes it\n\t// used: a cross-site iframe can only clear `SameSite=None` cookies, which\n\t// `draftMode().disable()` does not use in development.\n\tconst cookieJar = await cookies()\n\tconst cookieAttributes = previewCookieAttributes((await headers()).get(\"host\"))\n\tcookieJar.delete({ name: \"__prerender_bypass\", httpOnly: true, ...cookieAttributes })\n\tcookieJar.delete({ name: prismicCookie.preview, ...cookieAttributes })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAmBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,SAAS,WAAW,YAAY,MAAM,OAAO;AAEpD,EAAC,MAAM,WAAW,EAAE,SAAS;CAK9B,MAAM,YAAY,MAAM,SAAS;CACjC,MAAM,mBAAmBA,gCAAAA,yBAAyB,MAAM,SAAS,EAAE,IAAI,OAAO,CAAC;AAC/E,WAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAM,GAAG;EAAkB,CAAC;AACrF,WAAU,OAAO;EAAE,MAAMC,kBAAAA,OAAc;EAAS,GAAG;EAAkB,CAAC;AAGtE,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"exitPreview.d.cts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAmBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAiBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
1
+ {"version":3,"file":"exitPreview.d.ts","names":[],"sources":["../src/exitPreview.ts"],"mappings":";;AAmBA;;;;;;;;;;;;;;iBAAsB,WAAA,CAAA,GAAe,OAAA,CAAQ,QAAA"}
@@ -1,3 +1,4 @@
1
+ import { previewCookieAttributes } from "./lib/previewCookieAttributes.js";
1
2
  import { cookie } from "@prismicio/client";
2
3
  //#region src/exitPreview.ts
3
4
  /**
@@ -16,17 +17,18 @@ import { cookie } from "@prismicio/client";
16
17
  * ```
17
18
  */
18
19
  async function exitPreview() {
19
- const { cookies } = await import("next/headers.js");
20
+ const { cookies, draftMode, headers } = await import("next/headers.js");
21
+ (await draftMode()).disable();
20
22
  const cookieJar = await cookies();
23
+ const cookieAttributes = previewCookieAttributes((await headers()).get("host"));
21
24
  cookieJar.delete({
22
25
  name: "__prerender_bypass",
23
- sameSite: "none",
24
- secure: true
26
+ httpOnly: true,
27
+ ...cookieAttributes
25
28
  });
26
29
  cookieJar.delete({
27
30
  name: cookie.preview,
28
- sameSite: "none",
29
- secure: true
31
+ ...cookieAttributes
30
32
  });
31
33
  return new Response(JSON.stringify({ success: true }), { headers: { "Cache-Control": "no-store" } });
32
34
  }
@@ -1 +1 @@
1
- {"version":3,"file":"exitPreview.js","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies } = await import(\"next/headers\")\n\n\t// Expire both cookies with the attributes `redirectToPreviewURL` used.\n\t// `draftMode().disable()` only expires the Draft Mode cookie, and with\n\t// `SameSite=Lax` in development, which a cross-site iframe cannot clear.\n\tconst cookieJar = await cookies()\n\tcookieJar.delete({ name: \"__prerender_bypass\", sameSite: \"none\", secure: true })\n\tcookieJar.delete({ name: prismicCookie.preview, sameSite: \"none\", secure: true })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,YAAY,MAAM,OAAO;CAKjC,MAAM,YAAY,MAAM,SAAS;AACjC,WAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAChF,WAAU,OAAO;EAAE,MAAMA,OAAc;EAAS,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGjF,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
1
+ {"version":3,"file":"exitPreview.js","names":["prismicCookie"],"sources":["../src/exitPreview.ts"],"sourcesContent":["import { cookie as prismicCookie } from \"@prismicio/client\"\n\nimport { previewCookieAttributes } from \"./lib/previewCookieAttributes\"\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be used in a Router\n * Handler.\n *\n * @example\n * \t;```typescript\n * \t// src/app/api/exit-preview/route.js\n *\n * \timport { exitPreview } from \"@prismicio/next\"\n *\n * \texport async function GET() {\n * \t\treturn await exitPreview()\n * \t}\n * \t```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode, headers } = await import(\"next/headers\")\n\n\t;(await draftMode()).disable()\n\n\t// Clear the cookies `redirectToPreviewURL` wrote with the attributes it\n\t// used: a cross-site iframe can only clear `SameSite=None` cookies, which\n\t// `draftMode().disable()` does not use in development.\n\tconst cookieJar = await cookies()\n\tconst cookieAttributes = previewCookieAttributes((await headers()).get(\"host\"))\n\tcookieJar.delete({ name: \"__prerender_bypass\", httpOnly: true, ...cookieAttributes })\n\tcookieJar.delete({ name: prismicCookie.preview, ...cookieAttributes })\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmBA,eAAsB,cAAiC;CAItD,MAAM,EAAE,SAAS,WAAW,YAAY,MAAM,OAAO;AAEpD,EAAC,MAAM,WAAW,EAAE,SAAS;CAK9B,MAAM,YAAY,MAAM,SAAS;CACjC,MAAM,mBAAmB,yBAAyB,MAAM,SAAS,EAAE,IAAI,OAAO,CAAC;AAC/E,WAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAM,GAAG;EAAkB,CAAC;AACrF,WAAU,OAAO;EAAE,MAAMA,OAAc;EAAS,GAAG;EAAkB,CAAC;AAGtE,QAAO,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,MAAM,CAAC,EAAE,EACtD,SAAS,EACR,iBAAiB,YACjB,EACD,CAAC"}
@@ -0,0 +1,20 @@
1
+ //#region src/lib/previewCookieAttributes.ts
2
+ /**
3
+ * Attributes for the preview cookie and Next.js's Draft Mode cookie.
4
+ *
5
+ * Browsers only send `SameSite=Lax` cookies on same-site requests, so the cookies need
6
+ * `SameSite=None; Secure` to work when the site is embedded in a cross-site iframe, like the
7
+ * Prismic editor. Browsers reject `Secure` cookies over plain HTTP unless the host is `localhost`,
8
+ * so `next dev` on any other host keeps Next.js's `Lax` default.
9
+ */
10
+ function previewCookieAttributes(host) {
11
+ const secure = process.env.NODE_ENV !== "development" || host?.split(":")[0] === "localhost";
12
+ return {
13
+ sameSite: secure ? "none" : "lax",
14
+ secure
15
+ };
16
+ }
17
+ //#endregion
18
+ exports.previewCookieAttributes = previewCookieAttributes;
19
+
20
+ //# sourceMappingURL=previewCookieAttributes.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"previewCookieAttributes.cjs","names":[],"sources":["../../src/lib/previewCookieAttributes.ts"],"sourcesContent":["/**\n * Attributes for the preview cookie and Next.js's Draft Mode cookie.\n *\n * Browsers only send `SameSite=Lax` cookies on same-site requests, so the cookies need\n * `SameSite=None; Secure` to work when the site is embedded in a cross-site iframe, like the\n * Prismic editor. Browsers reject `Secure` cookies over plain HTTP unless the host is `localhost`,\n * so `next dev` on any other host keeps Next.js's `Lax` default.\n */\nexport function previewCookieAttributes(host: string | null | undefined): {\n\tsameSite: \"none\" | \"lax\"\n\tsecure: boolean\n} {\n\tconst secure = process.env.NODE_ENV !== \"development\" || host?.split(\":\")[0] === \"localhost\"\n\n\treturn { sameSite: secure ? \"none\" : \"lax\", secure }\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,wBAAwB,MAGtC;CACD,MAAM,SAAS,QAAQ,IAAI,aAAa,iBAAiB,MAAM,MAAM,IAAI,CAAC,OAAO;AAEjF,QAAO;EAAE,UAAU,SAAS,SAAS;EAAO;EAAQ"}
@@ -0,0 +1,20 @@
1
+ //#region src/lib/previewCookieAttributes.ts
2
+ /**
3
+ * Attributes for the preview cookie and Next.js's Draft Mode cookie.
4
+ *
5
+ * Browsers only send `SameSite=Lax` cookies on same-site requests, so the cookies need
6
+ * `SameSite=None; Secure` to work when the site is embedded in a cross-site iframe, like the
7
+ * Prismic editor. Browsers reject `Secure` cookies over plain HTTP unless the host is `localhost`,
8
+ * so `next dev` on any other host keeps Next.js's `Lax` default.
9
+ */
10
+ function previewCookieAttributes(host) {
11
+ const secure = process.env.NODE_ENV !== "development" || host?.split(":")[0] === "localhost";
12
+ return {
13
+ sameSite: secure ? "none" : "lax",
14
+ secure
15
+ };
16
+ }
17
+ //#endregion
18
+ export { previewCookieAttributes };
19
+
20
+ //# sourceMappingURL=previewCookieAttributes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"previewCookieAttributes.js","names":[],"sources":["../../src/lib/previewCookieAttributes.ts"],"sourcesContent":["/**\n * Attributes for the preview cookie and Next.js's Draft Mode cookie.\n *\n * Browsers only send `SameSite=Lax` cookies on same-site requests, so the cookies need\n * `SameSite=None; Secure` to work when the site is embedded in a cross-site iframe, like the\n * Prismic editor. Browsers reject `Secure` cookies over plain HTTP unless the host is `localhost`,\n * so `next dev` on any other host keeps Next.js's `Lax` default.\n */\nexport function previewCookieAttributes(host: string | null | undefined): {\n\tsameSite: \"none\" | \"lax\"\n\tsecure: boolean\n} {\n\tconst secure = process.env.NODE_ENV !== \"development\" || host?.split(\":\")[0] === \"localhost\"\n\n\treturn { sameSite: secure ? \"none\" : \"lax\", secure }\n}\n"],"mappings":";;;;;;;;;AAQA,SAAgB,wBAAwB,MAGtC;CACD,MAAM,SAAS,QAAQ,IAAI,aAAa,iBAAiB,MAAM,MAAM,IAAI,CAAC,OAAO;AAEjF,QAAO;EAAE,UAAU,SAAS,SAAS;EAAO;EAAQ"}
package/dist/package.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.3.1-pr.148.cfcff00";
2
+ var version = "2.3.1-pr.148.d5dbc1a";
3
3
  //#endregion
4
4
  Object.defineProperty(exports, "version", {
5
5
  enumerable: true,
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "2.3.1-pr.148.cfcff00";
2
+ var version = "2.3.1-pr.148.d5dbc1a";
3
3
  //#endregion
4
4
  export { version };
5
5
 
@@ -1,4 +1,5 @@
1
1
  require("./_virtual/_rolldown/runtime.cjs");
2
+ const require_previewCookieAttributes = require("./lib/previewCookieAttributes.cjs");
2
3
  let _prismicio_client = require("@prismicio/client");
3
4
  //#region src/redirectToPreviewURL.ts
4
5
  async function redirectToPreviewURL(config) {
@@ -7,11 +8,9 @@ async function redirectToPreviewURL(config) {
7
8
  const { redirect } = await import("next/navigation");
8
9
  const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
9
10
  const cookieJar = await cookies();
11
+ const cookieAttributes = require_previewCookieAttributes.previewCookieAttributes(request.headers.get("host"));
10
12
  const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
11
- if (previewToken) cookieJar.set(_prismicio_client.cookie.preview, previewToken, {
12
- sameSite: "none",
13
- secure: true
14
- });
13
+ if (previewToken) cookieJar.set(_prismicio_client.cookie.preview, previewToken, cookieAttributes);
15
14
  const previewURL = await client.resolvePreviewURL({
16
15
  documentID,
17
16
  previewToken,
@@ -22,8 +21,7 @@ async function redirectToPreviewURL(config) {
22
21
  const draftCookie = cookieJar.get("__prerender_bypass");
23
22
  if (draftCookie) cookieJar.set({
24
23
  ...draftCookie,
25
- sameSite: "none",
26
- secure: true
24
+ ...cookieAttributes
27
25
  });
28
26
  return redirect(previewURL);
29
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.cjs","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\t//\n\t// Browsers only send `SameSite=Lax` cookies on same-site requests, so\n\t// `SameSite=None; Secure` is needed for the site to preview inside a\n\t// cross-site iframe, like the Prismic editor.\n\tconst cookieJar = await cookies()\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tcookieJar.set(prismicCookie.preview, previewToken, { sameSite: \"none\", secure: true })\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\t// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development.\n\t// Rewrite it like the preview cookie, keeping Next.js's value.\n\tconst draftCookie = cookieJar.get(\"__prerender_bypass\")\n\tif (draftCookie) {\n\t\tcookieJar.set({ ...draftCookie, sameSite: \"none\", secure: true })\n\t}\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAUrE,MAAM,YAAY,MAAM,SAAS;CACjC,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aACH,WAAU,IAAIA,kBAAAA,OAAc,SAAS,cAAc;EAAE,UAAU;EAAQ,QAAQ;EAAM,CAAC;CAGvF,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;CAI7B,MAAM,cAAc,UAAU,IAAI,qBAAqB;AACvD,KAAI,YACH,WAAU,IAAI;EAAE,GAAG;EAAa,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGlE,QAAO,SAAS,WAAW"}
1
+ {"version":3,"file":"redirectToPreviewURL.cjs","names":["previewCookieAttributes","prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport { previewCookieAttributes } from \"./lib/previewCookieAttributes\"\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\tconst cookieJar = await cookies()\n\tconst cookieAttributes = previewCookieAttributes(request.headers.get(\"host\"))\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tcookieJar.set(prismicCookie.preview, previewToken, cookieAttributes)\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\t// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development,\n\t// which cross-site iframes drop. Rewrite it with the preview cookie's\n\t// attributes, keeping Next.js's value.\n\tconst draftCookie = cookieJar.get(\"__prerender_bypass\")\n\tif (draftCookie) {\n\t\tcookieJar.set({ ...draftCookie, ...cookieAttributes })\n\t}\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;;AAmCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMrE,MAAM,YAAY,MAAM,SAAS;CACjC,MAAM,mBAAmBA,gCAAAA,wBAAwB,QAAQ,QAAQ,IAAI,OAAO,CAAC;CAC7E,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aACH,WAAU,IAAIC,kBAAAA,OAAc,SAAS,cAAc,iBAAiB;CAGrE,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;CAK7B,MAAM,cAAc,UAAU,IAAI,qBAAqB;AACvD,KAAI,YACH,WAAU,IAAI;EAAE,GAAG;EAAa,GAAG;EAAkB,CAAC;AAGvD,QAAO,SAAS,WAAW"}
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.d.cts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAIY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
1
+ {"version":3,"file":"redirectToPreviewURL.d.cts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAKY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.d.ts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAIY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
1
+ {"version":3,"file":"redirectToPreviewURL.d.ts","names":[],"sources":["../src/redirectToPreviewURL.ts"],"mappings":";;;;KAKY,0BAAA;4EAKX,MAAA,EAAQ,IAAA,CAAK,MAAA;EALwB;;;;;EAYrC,OAAA,EAAS,eAAA;EAO0B;;;;;EAAnC,YAAA,GAAe,oBAAA;EAPN;;;;;;EAeT,UAAA;AAAA;AAAA,iBAGqB,oBAAA,CAAqB,MAAA,EAAQ,0BAAA,GAA6B,OAAA"}
@@ -1,3 +1,4 @@
1
+ import { previewCookieAttributes } from "./lib/previewCookieAttributes.js";
1
2
  import { cookie } from "@prismicio/client";
2
3
  //#region src/redirectToPreviewURL.ts
3
4
  async function redirectToPreviewURL(config) {
@@ -6,11 +7,9 @@ async function redirectToPreviewURL(config) {
6
7
  const { redirect } = await import("next/navigation");
7
8
  const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
8
9
  const cookieJar = await cookies();
10
+ const cookieAttributes = previewCookieAttributes(request.headers.get("host"));
9
11
  const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
10
- if (previewToken) cookieJar.set(cookie.preview, previewToken, {
11
- sameSite: "none",
12
- secure: true
13
- });
12
+ if (previewToken) cookieJar.set(cookie.preview, previewToken, cookieAttributes);
14
13
  const previewURL = await client.resolvePreviewURL({
15
14
  documentID,
16
15
  previewToken,
@@ -21,8 +20,7 @@ async function redirectToPreviewURL(config) {
21
20
  const draftCookie = cookieJar.get("__prerender_bypass");
22
21
  if (draftCookie) cookieJar.set({
23
22
  ...draftCookie,
24
- sameSite: "none",
25
- secure: true
23
+ ...cookieAttributes
26
24
  });
27
25
  return redirect(previewURL);
28
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\t//\n\t// Browsers only send `SameSite=Lax` cookies on same-site requests, so\n\t// `SameSite=None; Secure` is needed for the site to preview inside a\n\t// cross-site iframe, like the Prismic editor.\n\tconst cookieJar = await cookies()\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tcookieJar.set(prismicCookie.preview, previewToken, { sameSite: \"none\", secure: true })\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\t// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development.\n\t// Rewrite it like the preview cookie, keeping Next.js's value.\n\tconst draftCookie = cookieJar.get(\"__prerender_bypass\")\n\tif (draftCookie) {\n\t\tcookieJar.set({ ...draftCookie, sameSite: \"none\", secure: true })\n\t}\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;AAkCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAUrE,MAAM,YAAY,MAAM,SAAS;CACjC,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aACH,WAAU,IAAIA,OAAc,SAAS,cAAc;EAAE,UAAU;EAAQ,QAAQ;EAAM,CAAC;CAGvF,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;CAI7B,MAAM,cAAc,UAAU,IAAI,qBAAqB;AACvD,KAAI,YACH,WAAU,IAAI;EAAE,GAAG;EAAa,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGlE,QAAO,SAAS,WAAW"}
1
+ {"version":3,"file":"redirectToPreviewURL.js","names":["prismicCookie"],"sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { cookie as prismicCookie, type Client, type LinkResolverFunction } from \"@prismicio/client\"\n\nimport { previewCookieAttributes } from \"./lib/previewCookieAttributes\"\nimport type { NextRequestLike } from \"./types\"\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the `defaultURL` option must\n\t * _not_ include it. Instead, provide the `basePath` property using the `basePath` option.\n\t */\n\tdefaultURL?: string\n}\n\nexport async function redirectToPreviewURL(config: RedirectToPreviewURLConfig): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\")\n\n\t// Dynamic so Node.js can load this module: the bare specifier (kept by\n\t// tsdown.config.ts for Next.js's server alias) is not resolvable by Node.js.\n\tconst { redirect } = await import(\"next/navigation\")\n\n\tconst documentID = request.nextUrl.searchParams.get(\"documentId\") ?? undefined\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\tconst cookieJar = await cookies()\n\tconst cookieAttributes = previewCookieAttributes(request.headers.get(\"host\"))\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined\n\tif (previewToken) {\n\t\tcookieJar.set(prismicCookie.preview, previewToken, cookieAttributes)\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t})\n\n\t;(await draftMode()).enable()\n\n\t// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development,\n\t// which cross-site iframes drop. Rewrite it with the preview cookie's\n\t// attributes, keeping Next.js's value.\n\tconst draftCookie = cookieJar.get(\"__prerender_bypass\")\n\tif (draftCookie) {\n\t\tcookieJar.set({ ...draftCookie, ...cookieAttributes })\n\t}\n\n\treturn redirect(previewURL)\n}\n"],"mappings":";;;AAmCA,eAAsB,qBAAqB,QAAoD;CAC9F,MAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;CAK5D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO;CAI5C,MAAM,EAAE,aAAa,MAAM,OAAO;CAElC,MAAM,aAAa,QAAQ,QAAQ,aAAa,IAAI,aAAa,IAAI,KAAA;CAMrE,MAAM,YAAY,MAAM,SAAS;CACjC,MAAM,mBAAmB,wBAAwB,QAAQ,QAAQ,IAAI,OAAO,CAAC;CAC7E,MAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,QAAQ,IAAI,KAAA;AAClE,KAAI,aACH,WAAU,IAAIA,OAAc,SAAS,cAAc,iBAAiB;CAGrE,MAAM,aAAa,MAAM,OAAO,kBAAkB;EACjD;EACA;EACA;EACA;EACA,CAAC;AAED,EAAC,MAAM,WAAW,EAAE,QAAQ;CAK7B,MAAM,cAAc,UAAU,IAAI,qBAAqB;AACvD,KAAI,YACH,WAAU,IAAI;EAAE,GAAG;EAAa,GAAG;EAAkB,CAAC;AAGvD,QAAO,SAAS,WAAW"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "2.3.1-pr.148.cfcff00",
3
+ "version": "2.3.1-pr.148.d5dbc1a",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "next",
@@ -1,5 +1,7 @@
1
1
  import { cookie as prismicCookie } from "@prismicio/client"
2
2
 
3
+ import { previewCookieAttributes } from "./lib/previewCookieAttributes"
4
+
3
5
  /**
4
6
  * Ends a Prismic preview session within a Next.js app. This function should be used in a Router
5
7
  * Handler.
@@ -19,14 +21,17 @@ export async function exitPreview(): Promise<Response> {
19
21
  // Need this to avoid the following Next.js build-time error:
20
22
  // You're importing a component that needs next/headers. That only works
21
23
  // in a Server Component which is not supported in the pages/ directory.
22
- const { cookies } = await import("next/headers")
24
+ const { cookies, draftMode, headers } = await import("next/headers")
25
+
26
+ ;(await draftMode()).disable()
23
27
 
24
- // Expire both cookies with the attributes `redirectToPreviewURL` used.
25
- // `draftMode().disable()` only expires the Draft Mode cookie, and with
26
- // `SameSite=Lax` in development, which a cross-site iframe cannot clear.
28
+ // Clear the cookies `redirectToPreviewURL` wrote with the attributes it
29
+ // used: a cross-site iframe can only clear `SameSite=None` cookies, which
30
+ // `draftMode().disable()` does not use in development.
27
31
  const cookieJar = await cookies()
28
- cookieJar.delete({ name: "__prerender_bypass", sameSite: "none", secure: true })
29
- cookieJar.delete({ name: prismicCookie.preview, sameSite: "none", secure: true })
32
+ const cookieAttributes = previewCookieAttributes((await headers()).get("host"))
33
+ cookieJar.delete({ name: "__prerender_bypass", httpOnly: true, ...cookieAttributes })
34
+ cookieJar.delete({ name: prismicCookie.preview, ...cookieAttributes })
30
35
 
31
36
  // `Cache-Control` header is used to prevent CDN-level caching.
32
37
  return new Response(JSON.stringify({ success: true }), {
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Attributes for the preview cookie and Next.js's Draft Mode cookie.
3
+ *
4
+ * Browsers only send `SameSite=Lax` cookies on same-site requests, so the cookies need
5
+ * `SameSite=None; Secure` to work when the site is embedded in a cross-site iframe, like the
6
+ * Prismic editor. Browsers reject `Secure` cookies over plain HTTP unless the host is `localhost`,
7
+ * so `next dev` on any other host keeps Next.js's `Lax` default.
8
+ */
9
+ export function previewCookieAttributes(host: string | null | undefined): {
10
+ sameSite: "none" | "lax"
11
+ secure: boolean
12
+ } {
13
+ const secure = process.env.NODE_ENV !== "development" || host?.split(":")[0] === "localhost"
14
+
15
+ return { sameSite: secure ? "none" : "lax", secure }
16
+ }
@@ -1,5 +1,6 @@
1
1
  import { cookie as prismicCookie, type Client, type LinkResolverFunction } from "@prismicio/client"
2
2
 
3
+ import { previewCookieAttributes } from "./lib/previewCookieAttributes"
3
4
  import type { NextRequestLike } from "./types"
4
5
 
5
6
  export type RedirectToPreviewURLConfig = {
@@ -50,14 +51,11 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
50
51
  // to support unpublished previews. Without setting it here, the page
51
52
  // will try to render without the preview cookie, leading to a
52
53
  // PrismicNotFound error.
53
- //
54
- // Browsers only send `SameSite=Lax` cookies on same-site requests, so
55
- // `SameSite=None; Secure` is needed for the site to preview inside a
56
- // cross-site iframe, like the Prismic editor.
57
54
  const cookieJar = await cookies()
55
+ const cookieAttributes = previewCookieAttributes(request.headers.get("host"))
58
56
  const previewToken = request.nextUrl.searchParams.get("token") ?? undefined
59
57
  if (previewToken) {
60
- cookieJar.set(prismicCookie.preview, previewToken, { sameSite: "none", secure: true })
58
+ cookieJar.set(prismicCookie.preview, previewToken, cookieAttributes)
61
59
  }
62
60
 
63
61
  const previewURL = await client.resolvePreviewURL({
@@ -69,11 +67,12 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
69
67
 
70
68
  ;(await draftMode()).enable()
71
69
 
72
- // Next.js writes its Draft Mode cookie as `SameSite=Lax` in development.
73
- // Rewrite it like the preview cookie, keeping Next.js's value.
70
+ // Next.js writes its Draft Mode cookie as `SameSite=Lax` in development,
71
+ // which cross-site iframes drop. Rewrite it with the preview cookie's
72
+ // attributes, keeping Next.js's value.
74
73
  const draftCookie = cookieJar.get("__prerender_bypass")
75
74
  if (draftCookie) {
76
- cookieJar.set({ ...draftCookie, sameSite: "none", secure: true })
75
+ cookieJar.set({ ...draftCookie, ...cookieAttributes })
77
76
  }
78
77
 
79
78
  return redirect(previewURL)