Skip to content

Commit 26b4782

Browse files
committed
chore: handle draft mode with bypass support
1 parent b6063ba commit 26b4782

File tree

7 files changed

+59
-39
lines changed

7 files changed

+59
-39
lines changed
+6-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import {redirect} from 'next/navigation'
1+
import {defineEnableDraftMode} from 'next-sanity/draft-mode'
2+
import {client} from '../../sanity.client'
3+
import {token} from '../../sanity.fetch'
24

3-
import {draftMode} from 'next/headers'
4-
5-
export async function GET(request: Request) {
6-
;(await draftMode()).enable()
7-
redirect('/')
8-
}
5+
export const {GET} = defineEnableDraftMode({
6+
client: client.withConfig({token}),
7+
})

apps/next-pages-router/next-env.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference types="next/navigation-types/compat/navigation" />
34

45
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
6+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

apps/next-pages-router/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"groq": "3.71.0",
2020
"groqd": "0.15.12",
2121
"next": "15.1.6",
22+
"next-sanity": "9.8.39",
2223
"react": "19.0.0",
2324
"react-dom": "19.0.0",
2425
"ui": "workspace:*"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {defineEnableDraftMode} from 'next-sanity/draft-mode'
2+
import {client} from '../../../sanity.client'
3+
import {token} from '../../../sanity.fetch'
4+
5+
export const {GET} = defineEnableDraftMode({
6+
client: client.withConfig({token}),
7+
})

apps/next-pages-router/src/pages/api/draft.ts

-7
This file was deleted.

packages/preview-kit/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"mendoza": "3.0.8"
9090
},
9191
"devDependencies": {
92-
"@sanity/client": "^6.25.0",
92+
"@sanity/client": "^6.27.0",
9393
"@sanity/pkg-utils": "7.0.2",
9494
"@sanity/prettier-config": "^1.0.3",
9595
"@sanity/semantic-release-preset": "^5.0.0",
@@ -120,7 +120,7 @@
120120
"vitest-github-actions-reporter": "^0.11.1"
121121
},
122122
"peerDependencies": {
123-
"@sanity/client": "^6.25.0",
123+
"@sanity/client": "^6.27.0",
124124
"react": "^18.0.0 || >=19.0.0-rc"
125125
},
126126
"peerDependenciesMeta": {

pnpm-lock.yaml

+41-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)