@prismicio/next 2.3.1-pr.148.a101ed4 → 2.3.1-pr.148.cfcff00
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 +8 -3
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.js +8 -3
- package/dist/exitPreview.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/redirectToPreviewURL.cjs +8 -1
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.js +8 -1
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/package.json +1 -1
- package/src/exitPreview.ts +7 -7
- package/src/redirectToPreviewURL.ts +11 -3
package/dist/exitPreview.cjs
CHANGED
|
@@ -17,9 +17,14 @@ let _prismicio_client = require("@prismicio/client");
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
async function exitPreview() {
|
|
20
|
-
const { cookies
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const { cookies } = await import("next/headers.js");
|
|
21
|
+
const cookieJar = await cookies();
|
|
22
|
+
cookieJar.delete({
|
|
23
|
+
name: "__prerender_bypass",
|
|
24
|
+
sameSite: "none",
|
|
25
|
+
secure: true
|
|
26
|
+
});
|
|
27
|
+
cookieJar.delete({
|
|
23
28
|
name: _prismicio_client.cookie.preview,
|
|
24
29
|
sameSite: "none",
|
|
25
30
|
secure: true
|
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
|
|
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"}
|
package/dist/exitPreview.js
CHANGED
|
@@ -16,9 +16,14 @@ import { cookie } from "@prismicio/client";
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
async function exitPreview() {
|
|
19
|
-
const { cookies
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const { cookies } = await import("next/headers.js");
|
|
20
|
+
const cookieJar = await cookies();
|
|
21
|
+
cookieJar.delete({
|
|
22
|
+
name: "__prerender_bypass",
|
|
23
|
+
sameSite: "none",
|
|
24
|
+
secure: true
|
|
25
|
+
});
|
|
26
|
+
cookieJar.delete({
|
|
22
27
|
name: cookie.preview,
|
|
23
28
|
sameSite: "none",
|
|
24
29
|
secure: true
|
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
|
|
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"}
|
package/dist/package.cjs
CHANGED
package/dist/package.js
CHANGED
|
@@ -6,8 +6,9 @@ async function redirectToPreviewURL(config) {
|
|
|
6
6
|
const { cookies, draftMode } = await import("next/headers.js");
|
|
7
7
|
const { redirect } = await import("next/navigation");
|
|
8
8
|
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
9
|
+
const cookieJar = await cookies();
|
|
9
10
|
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
10
|
-
if (previewToken)
|
|
11
|
+
if (previewToken) cookieJar.set(_prismicio_client.cookie.preview, previewToken, {
|
|
11
12
|
sameSite: "none",
|
|
12
13
|
secure: true
|
|
13
14
|
});
|
|
@@ -18,6 +19,12 @@ async function redirectToPreviewURL(config) {
|
|
|
18
19
|
linkResolver
|
|
19
20
|
});
|
|
20
21
|
(await draftMode()).enable();
|
|
22
|
+
const draftCookie = cookieJar.get("__prerender_bypass");
|
|
23
|
+
if (draftCookie) cookieJar.set({
|
|
24
|
+
...draftCookie,
|
|
25
|
+
sameSite: "none",
|
|
26
|
+
secure: true
|
|
27
|
+
});
|
|
21
28
|
return redirect(previewURL);
|
|
22
29
|
}
|
|
23
30
|
//#endregion
|
|
@@ -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// `SameSite=
|
|
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"}
|
|
@@ -5,8 +5,9 @@ async function redirectToPreviewURL(config) {
|
|
|
5
5
|
const { cookies, draftMode } = await import("next/headers.js");
|
|
6
6
|
const { redirect } = await import("next/navigation");
|
|
7
7
|
const documentID = request.nextUrl.searchParams.get("documentId") ?? void 0;
|
|
8
|
+
const cookieJar = await cookies();
|
|
8
9
|
const previewToken = request.nextUrl.searchParams.get("token") ?? void 0;
|
|
9
|
-
if (previewToken)
|
|
10
|
+
if (previewToken) cookieJar.set(cookie.preview, previewToken, {
|
|
10
11
|
sameSite: "none",
|
|
11
12
|
secure: true
|
|
12
13
|
});
|
|
@@ -17,6 +18,12 @@ async function redirectToPreviewURL(config) {
|
|
|
17
18
|
linkResolver
|
|
18
19
|
});
|
|
19
20
|
(await draftMode()).enable();
|
|
21
|
+
const draftCookie = cookieJar.get("__prerender_bypass");
|
|
22
|
+
if (draftCookie) cookieJar.set({
|
|
23
|
+
...draftCookie,
|
|
24
|
+
sameSite: "none",
|
|
25
|
+
secure: true
|
|
26
|
+
});
|
|
20
27
|
return redirect(previewURL);
|
|
21
28
|
}
|
|
22
29
|
//#endregion
|
|
@@ -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// `SameSite=
|
|
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"}
|
package/package.json
CHANGED
package/src/exitPreview.ts
CHANGED
|
@@ -19,14 +19,14 @@ 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
|
|
22
|
+
const { cookies } = await import("next/headers")
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// `
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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.
|
|
27
|
+
const cookieJar = await cookies()
|
|
28
|
+
cookieJar.delete({ name: "__prerender_bypass", sameSite: "none", secure: true })
|
|
29
|
+
cookieJar.delete({ name: prismicCookie.preview, sameSite: "none", secure: true })
|
|
30
30
|
|
|
31
31
|
// `Cache-Control` header is used to prevent CDN-level caching.
|
|
32
32
|
return new Response(JSON.stringify({ success: true }), {
|
|
@@ -51,11 +51,12 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
|
|
|
51
51
|
// will try to render without the preview cookie, leading to a
|
|
52
52
|
// PrismicNotFound error.
|
|
53
53
|
//
|
|
54
|
-
// `SameSite=
|
|
55
|
-
//
|
|
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
|
+
const cookieJar = await cookies()
|
|
56
58
|
const previewToken = request.nextUrl.searchParams.get("token") ?? undefined
|
|
57
59
|
if (previewToken) {
|
|
58
|
-
const cookieJar = await cookies()
|
|
59
60
|
cookieJar.set(prismicCookie.preview, previewToken, { sameSite: "none", secure: true })
|
|
60
61
|
}
|
|
61
62
|
|
|
@@ -68,5 +69,12 @@ export async function redirectToPreviewURL(config: RedirectToPreviewURLConfig):
|
|
|
68
69
|
|
|
69
70
|
;(await draftMode()).enable()
|
|
70
71
|
|
|
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.
|
|
74
|
+
const draftCookie = cookieJar.get("__prerender_bypass")
|
|
75
|
+
if (draftCookie) {
|
|
76
|
+
cookieJar.set({ ...draftCookie, sameSite: "none", secure: true })
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
return redirect(previewURL)
|
|
72
80
|
}
|