@prismicio/next 2.3.1-pr.148.cfcff00 → 2.3.1-pr.148.e767c38
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.
- package/dist/exitPreview.cjs +3 -1
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.js +3 -1
- package/dist/exitPreview.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/package.json +1 -1
- package/src/exitPreview.ts +7 -5
- package/src/redirectToPreviewURL.ts +3 -2
package/dist/exitPreview.cjs
CHANGED
|
@@ -17,10 +17,12 @@ let _prismicio_client = require("@prismicio/client");
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
async function exitPreview() {
|
|
20
|
-
const { cookies } = await import("next/headers.js");
|
|
20
|
+
const { cookies, draftMode } = await import("next/headers.js");
|
|
21
|
+
(await draftMode()).disable();
|
|
21
22
|
const cookieJar = await cookies();
|
|
22
23
|
cookieJar.delete({
|
|
23
24
|
name: "__prerender_bypass",
|
|
25
|
+
httpOnly: true,
|
|
24
26
|
sameSite: "none",
|
|
25
27
|
secure: true
|
|
26
28
|
});
|
package/dist/exitPreview.cjs.map
CHANGED
|
@@ -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//
|
|
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, draftMode } = 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\tcookieJar.delete({ name: \"__prerender_bypass\", httpOnly: true, 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,SAAS,cAAc,MAAM,OAAO;AAE3C,EAAC,MAAM,WAAW,EAAE,SAAS;CAK9B,MAAM,YAAY,MAAM,SAAS;AACjC,WAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAM,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAChG,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"}
|
package/dist/exitPreview.js
CHANGED
|
@@ -16,10 +16,12 @@ import { cookie } from "@prismicio/client";
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
async function exitPreview() {
|
|
19
|
-
const { cookies } = await import("next/headers.js");
|
|
19
|
+
const { cookies, draftMode } = await import("next/headers.js");
|
|
20
|
+
(await draftMode()).disable();
|
|
20
21
|
const cookieJar = await cookies();
|
|
21
22
|
cookieJar.delete({
|
|
22
23
|
name: "__prerender_bypass",
|
|
24
|
+
httpOnly: true,
|
|
23
25
|
sameSite: "none",
|
|
24
26
|
secure: true
|
|
25
27
|
});
|
package/dist/exitPreview.js.map
CHANGED
|
@@ -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//
|
|
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, draftMode } = 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\tcookieJar.delete({ name: \"__prerender_bypass\", httpOnly: true, 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,SAAS,cAAc,MAAM,OAAO;AAE3C,EAAC,MAAM,WAAW,EAAE,SAAS;CAK9B,MAAM,YAAY,MAAM,SAAS;AACjC,WAAU,OAAO;EAAE,MAAM;EAAsB,UAAU;EAAM,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAChG,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"}
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
|
@@ -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
|
|
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// which cross-site iframes drop. Rewrite it like the preview cookie,\n\t// 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;CAK7B,MAAM,cAAc,UAAU,IAAI,qBAAqB;AACvD,KAAI,YACH,WAAU,IAAI;EAAE,GAAG;EAAa,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGlE,QAAO,SAAS,WAAW"}
|
|
@@ -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
|
|
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// which cross-site iframes drop. Rewrite it like the preview cookie,\n\t// 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;CAK7B,MAAM,cAAc,UAAU,IAAI,qBAAqB;AACvD,KAAI,YACH,WAAU,IAAI;EAAE,GAAG;EAAa,UAAU;EAAQ,QAAQ;EAAM,CAAC;AAGlE,QAAO,SAAS,WAAW"}
|
package/package.json
CHANGED
package/src/exitPreview.ts
CHANGED
|
@@ -19,13 +19,15 @@ export async function exitPreview(): Promise<Response> {
|
|
|
19
19
|
// Need this to avoid the following Next.js build-time error:
|
|
20
20
|
// You're importing a component that needs next/headers. That only works
|
|
21
21
|
// in a Server Component which is not supported in the pages/ directory.
|
|
22
|
-
const { cookies } = await import("next/headers")
|
|
22
|
+
const { cookies, draftMode } = await import("next/headers")
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
24
|
+
;(await draftMode()).disable()
|
|
25
|
+
|
|
26
|
+
// Clear the cookies `redirectToPreviewURL` wrote with the attributes it
|
|
27
|
+
// used: a cross-site iframe can only clear `SameSite=None` cookies, which
|
|
28
|
+
// `draftMode().disable()` does not use in development.
|
|
27
29
|
const cookieJar = await cookies()
|
|
28
|
-
cookieJar.delete({ name: "__prerender_bypass", sameSite: "none", secure: true })
|
|
30
|
+
cookieJar.delete({ name: "__prerender_bypass", httpOnly: true, sameSite: "none", secure: true })
|
|
29
31
|
cookieJar.delete({ name: prismicCookie.preview, sameSite: "none", secure: true })
|
|
30
32
|
|
|
31
33
|
// `Cache-Control` header is used to prevent CDN-level caching.
|
|
@@ -69,8 +69,9 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
|
|
|
69
69
|
|
|
70
70
|
;(await draftMode()).enable()
|
|
71
71
|
|
|
72
|
-
// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development
|
|
73
|
-
// Rewrite it like the preview cookie,
|
|
72
|
+
// Next.js writes its Draft Mode cookie as `SameSite=Lax` in development,
|
|
73
|
+
// which cross-site iframes drop. Rewrite it like the preview cookie,
|
|
74
|
+
// keeping Next.js's value.
|
|
74
75
|
const draftCookie = cookieJar.get("__prerender_bypass")
|
|
75
76
|
if (draftCookie) {
|
|
76
77
|
cookieJar.set({ ...draftCookie, sameSite: "none", secure: true })
|