Unverified Commit 68b51415 authored by Steven's avatar Steven Committed by GitHub

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
parent cad6d3aa
...@@ -4,8 +4,8 @@ export default async function handler( ...@@ -4,8 +4,8 @@ export default async function handler(
_req: NextApiRequest, _req: NextApiRequest,
res: NextApiResponse res: NextApiResponse
) { ) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -19,8 +19,8 @@ export default async function handler( ...@@ -19,8 +19,8 @@ export default async function handler(
return res.status(401).end(`${validationResp.message}`) return res.status(401).end(`${validationResp.message}`)
} }
//enable preview mode // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the slug // Redirect to the slug
if (!('slug' in validationResp)) { if (!('slug' in validationResp)) {
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -15,8 +15,8 @@ export default async function preview(req, res) { ...@@ -15,8 +15,8 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
export default function exit(_, res) { export default function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -18,8 +18,8 @@ export default async function preview(req, res) { ...@@ -18,8 +18,8 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -18,8 +18,8 @@ export default async function preview(req, res) { ...@@ -18,8 +18,8 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -15,8 +15,8 @@ export default async function preview(req, res) { ...@@ -15,8 +15,8 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
const url = `/posts/${post.post.urlTitle}` const url = `/posts/${post.post.urlTitle}`
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -9,7 +9,7 @@ export default async function preview(req, res) { ...@@ -9,7 +9,7 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid token' }) return res.status(401).json({ message: 'Invalid token' })
} }
res.setPreviewData({}) res.setDraftMode({ enable: true })
res.redirect('/') res.redirect('/')
} }
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -18,8 +18,8 @@ export default async function preview(req, res) { ...@@ -18,8 +18,8 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
export default async function handler(_, res) { export default async function handler(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -18,8 +18,8 @@ export default async function handler(req, res) { ...@@ -18,8 +18,8 @@ export default async function handler(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
import { NextApiResponse } from 'next' import { NextApiResponse } from 'next'
export default async function exit(_: any, res: NextApiResponse) { export default async function exit(_: any, res: NextApiResponse) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -24,8 +24,8 @@ export default async function preview( ...@@ -24,8 +24,8 @@ export default async function preview(
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Preview Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -19,8 +19,8 @@ export default async function preview(req, res) { ...@@ -19,8 +19,8 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
export default async function handler(_, res) { export default async function handler(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -15,8 +15,8 @@ export default async function handler(req, res) { ...@@ -15,8 +15,8 @@ export default async function handler(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -2,8 +2,8 @@ import { postBySlugQuery } from '../../lib/queries' ...@@ -2,8 +2,8 @@ import { postBySlugQuery } from '../../lib/queries'
import { previewClient } from '../../lib/sanity.server' import { previewClient } from '../../lib/sanity.server'
function redirectToPreview(res, Location) { function redirectToPreview(res, Location) {
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to a preview capable route // Redirect to a preview capable route
res.writeHead(307, { Location }) res.writeHead(307, { Location })
res.end() res.end()
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -18,8 +18,8 @@ export default async function preview(req, res) { ...@@ -18,8 +18,8 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -18,8 +18,8 @@ export default async function preview(req, res) { ...@@ -18,8 +18,8 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
export default async function handler(_, res) { export default async function handler(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -18,8 +18,8 @@ export default async function handler(req, res) { ...@@ -18,8 +18,8 @@ export default async function handler(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
export default async function exit(_, res) { export default async function exit(_, res) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
...@@ -15,8 +15,8 @@ export default async function preview(req, res) { ...@@ -15,8 +15,8 @@ export default async function preview(req, res) {
return res.status(401).json({ message: 'Invalid slug' }) return res.status(401).json({ message: 'Invalid slug' })
} }
// Enable Preview Mode by setting the cookies // Enable Draft Mode by setting the cookie
res.setPreviewData({}) res.setDraftMode({ enable: true })
// Redirect to the path from the fetched post // Redirect to the path from the fetched post
// We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities // We don't redirect to req.query.slug as that might lead to open redirect vulnerabilities
......
import { NextApiResponse } from 'next' import { NextApiResponse } from 'next'
export default async function exit(_, res: NextApiResponse) { export default async function exit(_, res: NextApiResponse) {
// Exit the current user from "Preview Mode". This function accepts no args. // Exit Draft Mode by removing the cookie
res.clearPreviewData() res.setDraftMode({ enable: false })
// Redirect the user back to the index page. // Redirect the user back to the index page.
res.writeHead(307, { Location: '/' }) res.writeHead(307, { Location: '/' })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment