Skip to content

Commit

Permalink
Upgrade to NextJS 15 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish authored Oct 23, 2024
1 parent 8587601 commit 4500314
Show file tree
Hide file tree
Showing 61 changed files with 15,917 additions and 5,119 deletions.
2 changes: 1 addition & 1 deletion .storybook/stories/config-pages/GlobalMessage.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {Meta, StoryObj} from "@storybook/react"
import GlobalMessage from "@components/config-pages/global-message"
import {ComponentProps} from "react"
import {Link, StanfordGlobalMessage, Text} from "@lib/gql/__generated__/drupal"
import {Link, StanfordGlobalMessage, Text} from "@lib/gql/__generated__/drupal.d"
import {createMock} from "storybook-addon-module-mock"
import * as gql from "@lib/gql/gql-queries"

Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/config-pages/LocalFooter.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import LocalFooter from "@components/config-pages/local-footer"
import {ComponentProps} from "react"
import {createMock} from "storybook-addon-module-mock"
import * as gql from "@lib/gql/gql-queries"
import {StanfordLocalFooter} from "@lib/gql/__generated__/drupal"
import {StanfordLocalFooter} from "@lib/gql/__generated__/drupal.d"

type ComponentStoryProps = ComponentProps<typeof LocalFooter> & {}

Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/config-pages/SuperFooter.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {Meta, StoryObj} from "@storybook/react"
import SuperFooter from "@components/config-pages/super-footer"
import {ComponentProps} from "react"
import {StanfordSuperFooter, Text} from "@lib/gql/__generated__/drupal"
import {StanfordSuperFooter, Text} from "@lib/gql/__generated__/drupal.d"
import {createMock} from "storybook-addon-module-mock"
import * as gql from "@lib/gql/gql-queries"

Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/elements/lockup/Lockup.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {Meta, StoryObj} from "@storybook/react"
import Lockup from "@components/elements/lockup/lockup"
import {ComponentProps} from "react"
import {Image, LockupSetting} from "@lib/gql/__generated__/drupal"
import {Image, LockupSetting} from "@lib/gql/__generated__/drupal.d"
import {createMock} from "storybook-addon-module-mock"
import * as gql from "@lib/gql/gql-queries"

Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/StanfordCourse.data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NodeStanfordCourse} from "@lib/gql/__generated__/drupal"
import {NodeStanfordCourse} from "@lib/gql/__generated__/drupal.d"

export const StanfordCourseData = () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/StanfordEvent.data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NodeStanfordEvent} from "@lib/gql/__generated__/drupal"
import {NodeStanfordEvent} from "@lib/gql/__generated__/drupal.d"

export const StanfordEventData = () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/StanfordEventSeries.data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NodeStanfordEventSeries} from "@lib/gql/__generated__/drupal"
import {NodeStanfordEventSeries} from "@lib/gql/__generated__/drupal.d"

export const StanfordEventSeriesData = () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/StanfordNews.data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NodeStanfordNews} from "@lib/gql/__generated__/drupal"
import {NodeStanfordNews} from "@lib/gql/__generated__/drupal.d"

export const StanfordNewsData = () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/StanfordPage.data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NodeStanfordPage} from "@lib/gql/__generated__/drupal"
import {NodeStanfordPage} from "@lib/gql/__generated__/drupal.d"

export const StanfordPageData = () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/StanfordPerson.data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NodeStanfordPerson} from "@lib/gql/__generated__/drupal"
import {NodeStanfordPerson} from "@lib/gql/__generated__/drupal.d"

export const StanfordPersonData = () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/StanfordPolicy.data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NodeStanfordPolicy} from "@lib/gql/__generated__/drupal"
import {NodeStanfordPolicy} from "@lib/gql/__generated__/drupal.d"

export const StanfordPolicyData = () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/StanfordPublication.data.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NodeStanfordPublication} from "@lib/gql/__generated__/drupal"
import {NodeStanfordPublication} from "@lib/gql/__generated__/drupal.d"

export const StanfordPublicationData = () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/cards/BasicPageCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordPageCard from "@components/nodes/cards/stanford-page/stanford-page-card"
import {StanfordPageData} from "../StanfordPage.data"
import {ComponentProps} from "react"
import {Text, Image, NodeStanfordPage} from "@lib/gql/__generated__/drupal"
import {Text, Image, NodeStanfordPage} from "@lib/gql/__generated__/drupal.d"
import {getStoryBookImage} from "../../storybook-entities"

type ComponentStoryProps = ComponentProps<typeof StanfordPageCard> & {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/cards/CourseCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordCourseCard from "@components/nodes/cards/stanford-course/stanford-course-card"
import {StanfordCourseData} from "../StanfordCourse.data"
import {ComponentProps} from "react"
import {NodeStanfordCourse, TermSuCourseSubject} from "@lib/gql/__generated__/drupal"
import {NodeStanfordCourse, TermSuCourseSubject} from "@lib/gql/__generated__/drupal.d"
import {getStoryBookTaxonomyTerm} from "../../storybook-entities"

type ComponentStoryProps = ComponentProps<typeof StanfordCourseCard> & {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/cards/EventCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordEventCard from "@components/nodes/cards/stanford-event/stanford-event-card"
import {StanfordEventData} from "../StanfordEvent.data"
import {ComponentProps} from "react"
import {NodeStanfordEvent, SmartDateType, TermStanfordEventType} from "@lib/gql/__generated__/drupal"
import {NodeStanfordEvent, SmartDateType, TermStanfordEventType} from "@lib/gql/__generated__/drupal.d"
import {getStoryBookTaxonomyTerm} from "../../storybook-entities"

type ComponentStoryProps = ComponentProps<typeof StanfordEventCard> & {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/cards/EventSeriesCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordEventSeriesCard from "@components/nodes/cards/stanford-event-series/stanford-event-series-card"
import {StanfordEventSeriesData} from "../StanfordEventSeries.data"
import {ComponentProps} from "react"
import {NodeStanfordEventSeries} from "@lib/gql/__generated__/drupal"
import {NodeStanfordEventSeries} from "@lib/gql/__generated__/drupal.d"

type ComponentStoryProps = ComponentProps<typeof StanfordEventSeriesCard> & {
title: NodeStanfordEventSeries["title"]
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/cards/NewsCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import StanfordNewsCard from "@components/nodes/cards/stanford-news/stanford-new
import {StanfordNewsData} from "../StanfordNews.data"
import {ComponentProps} from "react"
import {getStoryBookImage, getStoryBookTaxonomyTerm} from "../../storybook-entities"
import {DateTime, Image, NodeStanfordNews, TermStanfordNewsTopic} from "@lib/gql/__generated__/drupal"
import {DateTime, Image, NodeStanfordNews, TermStanfordNewsTopic} from "@lib/gql/__generated__/drupal.d"

type ComponentStoryProps = ComponentProps<typeof StanfordNewsCard> & {
title: NodeStanfordNews["title"]
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/cards/PersonCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordPersonCard from "@components/nodes/cards/stanford-person/stanford-person-card"
import {StanfordPersonData} from "../StanfordPerson.data"
import {ComponentProps} from "react"
import {Image, NodeStanfordPerson} from "@lib/gql/__generated__/drupal"
import {Image, NodeStanfordPerson} from "@lib/gql/__generated__/drupal.d"
import {getStoryBookImage} from "../../storybook-entities"

type ComponentStoryProps = ComponentProps<typeof StanfordPersonCard> & {
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/cards/PolicyCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordPolicyCard from "@components/nodes/cards/stanford-policy/stanford-policy-card"
import {StanfordPolicyData} from "../StanfordPolicy.data"
import {ComponentProps} from "react"
import {NodeStanfordPolicy, Text} from "@lib/gql/__generated__/drupal"
import {NodeStanfordPolicy, Text} from "@lib/gql/__generated__/drupal.d"

type ComponentStoryProps = ComponentProps<typeof StanfordPolicyCard> & {
title: NodeStanfordPolicy["title"]
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/nodes/cards/PublicationCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import StanfordPublicationCard from "@components/nodes/cards/stanford-publicatio
import {StanfordPublicationData} from "../StanfordPublication.data"
import {ComponentProps} from "react"
import {getStoryBookTaxonomyTerm} from "../../storybook-entities"
import {NodeStanfordPublication, TermStanfordPublicationTopic} from "@lib/gql/__generated__/drupal"
import {NodeStanfordPublication, TermStanfordPublicationTopic} from "@lib/gql/__generated__/drupal.d"

type ComponentStoryProps = ComponentProps<typeof StanfordPublicationCard> & {
title: NodeStanfordPublication["title"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordPageListItem from "@components/nodes/list-item/stanford-page/stanford-page-list-item"
import {PageCard} from "../cards/BasicPageCard.stories"
import {ComponentProps} from "react"
import {Image, NodeStanfordPage, Text} from "@lib/gql/__generated__/drupal"
import {Image, NodeStanfordPage, Text} from "@lib/gql/__generated__/drupal.d"
import {getStoryBookImage} from "../../storybook-entities"

type ComponentStoryProps = ComponentProps<typeof StanfordPageListItem> & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordCourseListItem from "@components/nodes/list-item/stanford-course/stanford-course-list-item"
import {CourseCard} from "../cards/CourseCard.stories"
import {ComponentProps} from "react"
import {NodeStanfordCourse, TermSuCourseSubject} from "@lib/gql/__generated__/drupal"
import {NodeStanfordCourse, TermSuCourseSubject} from "@lib/gql/__generated__/drupal.d"
import {getStoryBookTaxonomyTerm} from "../../storybook-entities"

type ComponentStoryProps = ComponentProps<typeof StanfordCourseListItem> & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordEventListItem from "@components/nodes/list-item/stanford-event/stanford-event-list-item"
import {EventCard} from "../cards/EventCard.stories"
import {ComponentProps} from "react"
import {NodeStanfordEvent, SmartDateType, TermStanfordEventType} from "@lib/gql/__generated__/drupal"
import {NodeStanfordEvent, SmartDateType, TermStanfordEventType} from "@lib/gql/__generated__/drupal.d"
import {getStoryBookTaxonomyTerm} from "../../storybook-entities"

type ComponentStoryProps = ComponentProps<typeof StanfordEventListItem> & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordEventSeriesListItem from "@components/nodes/list-item/stanford-event-series/stanford-event-series-list-item"
import {EventSeriesCard} from "../cards/EventSeriesCard.stories"
import {ComponentProps} from "react"
import {NodeStanfordEventSeries} from "@lib/gql/__generated__/drupal"
import {NodeStanfordEventSeries} from "@lib/gql/__generated__/drupal.d"

type ComponentStoryProps = ComponentProps<typeof StanfordEventSeriesListItem> & {
title: NodeStanfordEventSeries["title"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import StanfordNewsListItem from "@components/nodes/list-item/stanford-news/stan
import {NewsCard} from "../cards/NewsCard.stories"
import {ComponentProps} from "react"
import {getStoryBookImage, getStoryBookTaxonomyTerm} from "../../storybook-entities"
import {DateTime, Image, NodeStanfordNews, TermStanfordNewsTopic} from "@lib/gql/__generated__/drupal"
import {DateTime, Image, NodeStanfordNews, TermStanfordNewsTopic} from "@lib/gql/__generated__/drupal.d"

type ComponentStoryProps = ComponentProps<typeof StanfordNewsListItem> & {
title: NodeStanfordNews["title"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordPersonListItem from "@components/nodes/list-item/stanford-person/stanford-person-list-item"
import {PersonCard} from "../cards/PersonCard.stories"
import {ComponentProps} from "react"
import {Image, NodeStanfordPerson} from "@lib/gql/__generated__/drupal"
import {Image, NodeStanfordPerson} from "@lib/gql/__generated__/drupal.d"
import {getStoryBookImage} from "../../storybook-entities"

type ComponentStoryProps = ComponentProps<typeof StanfordPersonListItem> & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {Meta, StoryObj} from "@storybook/react"
import StanfordPolicyListItem from "@components/nodes/list-item/stanford-policy/stanford-policy-list-item"
import {PolicyCard} from "../cards/PolicyCard.stories"
import {ComponentProps} from "react"
import {NodeStanfordPolicy, Text} from "@lib/gql/__generated__/drupal"
import {NodeStanfordPolicy, Text} from "@lib/gql/__generated__/drupal.d"

type ComponentStoryProps = ComponentProps<typeof StanfordPolicyListItem> & {
title: NodeStanfordPolicy["title"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import StanfordPublicationListItem from "@components/nodes/list-item/stanford-pu
import {PublicationCard} from "../cards/PublicationCard.stories"
import {ComponentProps} from "react"
import {getStoryBookTaxonomyTerm} from "../../storybook-entities"
import {NodeStanfordPublication, TermStanfordPublicationTopic} from "@lib/gql/__generated__/drupal"
import {NodeStanfordPublication, TermStanfordPublicationTopic} from "@lib/gql/__generated__/drupal.d"

type ComponentStoryProps = ComponentProps<typeof StanfordPublicationListItem> & {
title: NodeStanfordPublication["title"]
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/paragraphs/Banner.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Meta, StoryObj} from "@storybook/react"
import {ComponentProps} from "react"
import {ParagraphStanfordBanner, Text} from "@lib/gql/__generated__/drupal"
import {ParagraphStanfordBanner, Text} from "@lib/gql/__generated__/drupal.d"
import BannerParagraph from "@components/paragraphs/stanford-banner/banner-paragraph"
import {getStoryBookImage} from "../storybook-entities"

Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/paragraphs/Card.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {Meta, StoryObj} from "@storybook/react"
import {ComponentProps} from "react"
import {ParagraphStanfordCard, Text} from "@lib/gql/__generated__/drupal"
import {ParagraphStanfordCard, Text} from "@lib/gql/__generated__/drupal.d"
import CardParagraph from "@components/paragraphs/stanford-card/card-paragraph"
import {getStoryBookImage} from "../storybook-entities"

Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/paragraphs/Wysiwyg.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {Meta, StoryObj} from "@storybook/react"
import WysiwygParagraph from "@components/paragraphs/stanford-wysiwyg/wysiwyg-paragraph"
import {ComponentProps} from "react"
import {ParagraphStanfordWysiwyg, Text} from "@lib/gql/__generated__/drupal"
import {ParagraphStanfordWysiwyg, Text} from "@lib/gql/__generated__/drupal.d"

type ComponentStoryProps = ComponentProps<typeof WysiwygParagraph> & {
text: Text["processed"]
Expand Down
2 changes: 1 addition & 1 deletion .storybook/stories/storybook-entities.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {MediaImage, MediaStanfordGalleryImage, MediaVideo, TermInterface} from "@lib/gql/__generated__/drupal"
import {MediaImage, MediaStanfordGalleryImage, MediaVideo, TermInterface} from "@lib/gql/__generated__/drupal.d"

export const getStoryBookImage = (imageUrl?: string): MediaImage => {
return {
Expand Down
21 changes: 13 additions & 8 deletions app/@modal/(.)gallery/[...uuid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import Link from "@components/elements/link"
import {ParagraphStanfordGallery} from "@lib/gql/__generated__/drupal.d"
import {graphqlClient} from "@lib/gql/gql-client"
import {notFound} from "next/navigation"
import {useId} from "react"

// https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
export const revalidate = false
export const dynamic = "force-static"
// https://vercel.com/docs/functions/runtimes#max-duration
export const maxDuration = 60

type Props = {
params: {uuid: string[]}
params: Promise<{uuid: string[]}>
}

const Page = async ({params: {uuid}}: Props) => {
const captionId = useId()
const [paragraphId, mediaUuid] = uuid
const Page = async (props: Props) => {
const params = await props.params
const [paragraphId, mediaUuid] = params.uuid

const paragraphQuery = await graphqlClient().Paragraph({uuid: paragraphId})
if (paragraphQuery.paragraph?.__typename !== "ParagraphStanfordGallery") notFound()
Expand All @@ -30,7 +35,7 @@ const Page = async ({params: {uuid}}: Props) => {
galleryImages = galleryImages?.filter(image => !!image.suGalleryImage?.url)

return (
<InterceptionModal aria-labelledby={captionId}>
<InterceptionModal aria-labelledby={mediaUuid}>
{galleryImages?.map(galleryImage => {
if (!galleryImage.suGalleryImage?.url) return

Expand All @@ -47,7 +52,7 @@ const Page = async ({params: {uuid}}: Props) => {
/>
</picture>
{galleryImage.suGalleryCaption && (
<figcaption id={captionId} className="m-0 table-caption w-full caption-bottom bg-white p-5 text-right">
<figcaption id={mediaUuid} className="m-0 table-caption w-full caption-bottom bg-white p-5 text-right">
{galleryImage.suGalleryCaption}
</figcaption>
)}
Expand Down Expand Up @@ -89,7 +94,7 @@ const Page = async ({params: {uuid}}: Props) => {
)
}

export const generateStaticParams = async (): Promise<Array<Props["params"]>> => {
export const generateStaticParams = async (): Promise<Array<{uuid: string[]}>> => {
return []
}

Expand Down
14 changes: 8 additions & 6 deletions app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import {NodeUnion} from "@lib/gql/__generated__/drupal.d"
import {getAllNodes, getEntityFromPath} from "@lib/gql/gql-queries"
import {getNodeMetadata} from "./metadata"
import {notFound, redirect} from "next/navigation"
import {getPathFromContext, PageProps} from "@lib/drupal/utils"
import {getPathFromContext, PageProps, Slug} from "@lib/drupal/utils"

// https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
export const revalidate = false
export const dynamic = "force-static"
// https://vercel.com/docs/functions/runtimes#max-duration
export const maxDuration = 60

const Page = async ({params}: PageProps) => {
const path = getPathFromContext({params})
const Page = async (props: PageProps) => {
const params = await props.params
const path = getPathFromContext(params.slug)
const {redirect: redirectPath, entity} = await getEntityFromPath<NodeUnion>(path)

if (redirectPath) redirect(redirectPath)
Expand All @@ -22,13 +23,14 @@ const Page = async ({params}: PageProps) => {
return <NodePage node={entity} />
}

export const generateMetadata = async ({params}: PageProps): Promise<Metadata> => {
const path = getPathFromContext({params})
export const generateMetadata = async (props: PageProps): Promise<Metadata> => {
const params = await props.params
const path = getPathFromContext(params.slug)
const {entity} = await getEntityFromPath<NodeUnion>(path)
return entity ? getNodeMetadata(entity) : {}
}

export const generateStaticParams = async (): Promise<PageProps["params"][]> => {
export const generateStaticParams = async (): Promise<Array<Slug>> => {
const pagesToBuild = parseInt(process.env.BUILD_PAGES || "0")
if (pagesToBuild === 0) return []
const nodePaths = (await getAllNodes()).map(node => ({slug: node.path.split("/").filter(part => !!part)}))
Expand Down
2 changes: 1 addition & 1 deletion app/api/draft/disable/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import {cookies} from "next/headers"
export const revalidate = 0

export const GET = async () => {
cookies().delete("preview")
;(await cookies()).delete("preview")
return NextResponse.json({disabled: true}, {status: 200})
}
4 changes: 2 additions & 2 deletions app/api/draft/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const GET = async (request: NextRequest) => {
if (!slug) {
return NextResponse.json({message: "Invalid slug path"}, {status: 401})
}
cookies().set("preview", secret, {
;(await cookies()).set("preview", secret, {
maxAge: 60 * 60,
httpOnly: true,
sameSite: "none",
Expand All @@ -26,6 +26,6 @@ export const GET = async (request: NextRequest) => {
})

// Redirect to the path from the fetched post
// We don"t redirect to searchParams.slug as that might lead to open redirect vulnerabilities
// We don't redirect to searchParams.slug as that might lead to open redirect vulnerabilities
redirect(`/preview${slug === "/home" ? "" : slug}`)
}
Loading

0 comments on commit 4500314

Please sign in to comment.