Skip to content

Commit 68b5141

Browse files
authored
chore: update examples to use draft mode (#49720)
This PR updates the examples to use Draft Mode introduced in [Next.js 13.4](https://nextjs.org/blog/next-13-4) fix NEXT-1153
1 parent cad6d3a commit 68b5141

File tree

35 files changed

+69
-69
lines changed

35 files changed

+69
-69
lines changed

examples/cms-agilitycms/pages/api/exit-preview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export default async function handler(
44
_req: NextApiRequest,
55
res: NextApiResponse
66
) {
7-
// Exit the current user from "Preview Mode". This function accepts no args.
8-
res.clearPreviewData()
7+
// Exit Draft Mode by removing the cookie
8+
res.setDraftMode({ enable: false })
99

1010
// Redirect the user back to the index page.
1111
res.writeHead(307, { Location: '/' })

examples/cms-agilitycms/pages/api/preview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export default async function handler(
1919
return res.status(401).end(`${validationResp.message}`)
2020
}
2121

22-
//enable preview mode
23-
res.setPreviewData({})
22+
// Enable Draft Mode by setting the cookie
23+
res.setDraftMode({ enable: true })
2424

2525
// Redirect to the slug
2626
if (!('slug' in validationResp)) {

examples/cms-builder-io/pages/api/exit-preview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default async function exit(_, res) {
2-
// Exit the current user from "Preview Mode". This function accepts no args.
3-
res.clearPreviewData()
2+
// Exit Draft Mode by removing the cookie
3+
res.setDraftMode({ enable: false })
44

55
// Redirect the user back to the index page.
66
res.writeHead(307, { Location: '/' })

examples/cms-contentful/pages/api/exit-preview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default async function exit(_, res) {
2-
// Exit the current user from "Preview Mode". This function accepts no args.
3-
res.clearPreviewData()
2+
// Exit Draft Mode by removing the cookie
3+
res.setDraftMode({ enable: false })
44

55
// Redirect the user back to the index page.
66
res.writeHead(307, { Location: '/' })

examples/cms-contentful/pages/api/preview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default async function preview(req, res) {
1515
return res.status(401).json({ message: 'Invalid slug' })
1616
}
1717

18-
// Enable Preview Mode by setting the cookies
19-
res.setPreviewData({})
18+
// Enable Draft Mode by setting the cookie
19+
res.setDraftMode({ enable: true })
2020

2121
// Redirect to the path from the fetched post
2222
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities

examples/cms-cosmic/pages/api/exit-preview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default function exit(_, res) {
2-
// Exit the current user from "Preview Mode". This function accepts no args.
3-
res.clearPreviewData()
2+
// Exit Draft Mode by removing the cookie
3+
res.setDraftMode({ enable: false })
44

55
// Redirect the user back to the index page.
66
res.writeHead(307, { Location: '/' })

examples/cms-cosmic/pages/api/preview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export default async function preview(req, res) {
1818
return res.status(401).json({ message: 'Invalid slug' })
1919
}
2020

21-
// Enable Preview Mode by setting the cookies
22-
res.setPreviewData({})
21+
// Enable Draft Mode by setting the cookie
22+
res.setDraftMode({ enable: true })
2323

2424
// Redirect to the path from the fetched post
2525
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities

examples/cms-datocms/pages/api/exit-preview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default async function exit(_, res) {
2-
// Exit the current user from "Preview Mode". This function accepts no args.
3-
res.clearPreviewData()
2+
// Exit Draft Mode by removing the cookie
3+
res.setDraftMode({ enable: false })
44

55
// Redirect the user back to the index page.
66
res.writeHead(307, { Location: '/' })

examples/cms-datocms/pages/api/preview.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ export default async function preview(req, res) {
1818
return res.status(401).json({ message: 'Invalid slug' })
1919
}
2020

21-
// Enable Preview Mode by setting the cookies
22-
res.setPreviewData({})
21+
// Enable Draft Mode by setting the cookie
22+
res.setDraftMode({ enable: true })
2323

2424
// Redirect to the path from the fetched post
2525
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities

examples/cms-dotcms/pages/api/exit-preview.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default async function exit(_, res) {
2-
// Exit the current user from "Preview Mode". This function accepts no args.
3-
res.clearPreviewData()
2+
// Exit Draft Mode by removing the cookie
3+
res.setDraftMode({ enable: false })
44

55
// Redirect the user back to the index page.
66
res.writeHead(307, { Location: '/' })

0 commit comments

Comments
 (0)