From ae873b5d3fd4c2215bbb7b3ccd65961aa4bdea9f Mon Sep 17 00:00:00 2001 From: Henrik Larsson Date: Wed, 23 Aug 2023 22:44:06 +0200 Subject: [PATCH] Next and next sanity fetching and preview updates --- app/(site)/[locale]/[...slug]/page.tsx | 1 - app/(site)/[locale]/page.tsx | 2 + app/api/preview/route.ts | 21 ++- app/globals.css | 32 +--- components/layout/footer/footer.tsx | 12 +- components/pages/product-page.tsx | 2 +- components/ui/sheet.tsx | 10 +- lib/sanity/constants.ts | 6 - lib/sanity/desk/index.ts | 8 +- lib/sanity/sanity.fetch.ts | 12 +- lib/sanity/sanity.types.ts | 6 + lib/sanity/schemas/documents/blurb.tsx | 70 ++++---- .../schemas/documents/productVariant.tsx | 30 ---- lib/sanity/schemas/index.ts | 2 - lib/sanity/utils/get-preview-url.ts | 2 +- package.json | 40 ++--- plugins/settings.tsx | 99 +++++++++++ pnpm-lock.yaml | 164 ++++++++++++------ sanity.config.ts | 94 ++++++++-- tailwind.config.js | 80 +++------ 20 files changed, 428 insertions(+), 265 deletions(-) delete mode 100644 lib/sanity/schemas/documents/productVariant.tsx create mode 100644 plugins/settings.tsx diff --git a/app/(site)/[locale]/[...slug]/page.tsx b/app/(site)/[locale]/[...slug]/page.tsx index 38146d096..c6e62f811 100644 --- a/app/(site)/[locale]/[...slug]/page.tsx +++ b/app/(site)/[locale]/[...slug]/page.tsx @@ -5,7 +5,6 @@ import ProductPagePreview from '@/components/pages/product-page-preview'; import SearchPage from '@/components/pages/search-page'; import SearchPagePreview from '@/components/pages/search-page-preview'; import SinglePage from '@/components/pages/single-page'; -// import PreviewProvider from '@/components/preview-provider'; import SinglePagePreview from '@/components/pages/single-page-preview'; import getQueryFromSlug from '@/helpers/get-query-from-slug'; import { categoryQuery, pageQuery, productQuery, searchPageQuery } from '@/lib/sanity/queries'; diff --git a/app/(site)/[locale]/page.tsx b/app/(site)/[locale]/page.tsx index 27d27392e..542665fb5 100644 --- a/app/(site)/[locale]/page.tsx +++ b/app/(site)/[locale]/page.tsx @@ -7,6 +7,8 @@ import { LiveQuery } from 'next-sanity/preview/live-query'; import { draftMode } from 'next/headers'; import { notFound } from 'next/navigation'; +export const runtime = 'edge'; + export async function generateMetadata({ params }: { diff --git a/app/api/preview/route.ts b/app/api/preview/route.ts index 8feb33431..241c62f22 100644 --- a/app/api/preview/route.ts +++ b/app/api/preview/route.ts @@ -1,5 +1,10 @@ +import { previewSecretId } from '@/lib/sanity/sanity.api' +import { client } from '@/lib/sanity/sanity.client' import { token } from '@/lib/sanity/sanity.fetch' import { draftMode } from 'next/headers' +import { isValidSecret } from 'sanity-plugin-iframe-pane/is-valid-secret' + +export const runtime = 'edge' export async function GET(request: Request) { const { searchParams } = new URL(request.url) @@ -14,8 +19,20 @@ export async function GET(request: Request) { ) } - if (secret !== process.env.SANITY_API_READ_TOKEN) { - return new Response('Invalid token', { status: 401 }) + if (!secret) { + return new Response('Invalid secret', { status: 401 }) + } + + const authenticatedClient = client.withConfig({ token }) + + const validSecret = await isValidSecret( + authenticatedClient, + previewSecretId, + secret, + ) + + if (!validSecret) { + return new Response('Invalid secret', { status: 401 }) } draftMode().enable() diff --git a/app/globals.css b/app/globals.css index 5434063cf..dcae2abe7 100644 --- a/app/globals.css +++ b/app/globals.css @@ -36,39 +36,12 @@ :root { --background: 0 0% 100%; --foreground: 0 0% 3.9%; - - --card: 0 0% 100%; - --card-foreground: 0 0% 3.9%; - - --popover: 0 0% 100%; - --popover-foreground: 0 0% 3.9%; - - --primary: 0 0% 9%; - --primary-foreground: 0 0% 98%; - - --secondary: 0 0% 96.1%; - --secondary-foreground: 0 0% 9%; - - --muted: 0 0% 96.1%; - --muted-foreground: 0 0% 45.1%; - - --accent: 0 0% 96.1%; - --accent-foreground: 0 0% 9%; - - --destructive: 0 84.2% 60.2%; - --destructive-foreground: 0 0% 98%; - --border: 0 0% 89.8%; --input: 0 0% 89.8%; --ring: 0 0% 3.9%; - --radius: 0.5rem; } - * { - @apply border-border; - } - ::-moz-selection { /* Code for Firefox */ color: #ffffff; @@ -82,7 +55,7 @@ html, body { - @apply h-full bg-white font-sans text-high-contrast; + @apply h-full bg-background text-foreground; box-sizing: border-box; touch-action: manipulation; @@ -91,9 +64,6 @@ -moz-osx-font-smoothing: grayscale; overscroll-behavior-x: none; } - body { - @apply bg-background text-foreground; - } } @layer components { diff --git a/components/layout/footer/footer.tsx b/components/layout/footer/footer.tsx index 8f9a9d3b0..7fede0a5a 100644 --- a/components/layout/footer/footer.tsx +++ b/components/layout/footer/footer.tsx @@ -1,5 +1,5 @@ -// import { footerMenusQuery } from '@/lib/sanity/queries'; -// import { getCachedClient } from '@/lib/sanity/sanity.client'; +import Text from '@/components/ui/text/text'; +import { getFooterMenus } from '@/lib/sanity/sanity.fetch'; import LocaleSwitcher from 'components/ui/locale-switcher/locale-switcher'; import Logo from 'components/ui/logo/logo'; import Link from 'next/link'; @@ -14,7 +14,7 @@ export default async function Footer({ locale }: FooterProps) { locale: locale }; - // const footerMenus = await getCachedClient()(footerMenusQuery, params); + const footerMenus = await getFooterMenus(params.locale); return (