#Forbidden: You are not allowed to perform this action. on generateStaticParams

1 messages · Page 1 of 1 (latest)

grizzled ocean
#

Server Error

Forbidden: You are not allowed to perform this action.

src/app/(site)/case-studies/[slug]/page.tsx (11:25) @ async Object.generateStaticParams

other imports..
import config from "@payload-config";
import { draftMode } from "next/headers";
import { getPayload } from "payload";
import { cache } from "react";

export async function generateStaticParams() {
const payload = await getPayload({ config });
const caseStudies = await payload.find({
collection: "case-studies",
draft: false,
limit: 1000,
overrideAccess: false,
pagination: false,
select: {
slug: true,
},
});

const params = caseStudies.docs.map(({ slug }) => {
    return { slug };
});

return params;

}

type Args = {
params: Promise<{
slug?: string;
}>;
};

export default async function CaseStudy({ params: paramsPromise }: Args) {
const { isEnabled: draft } = await draftMode();
const { slug = "" } = await paramsPromise;
const caseStudy = await queryCaseStudyBySlug({ slug });

if (!caseStudy) {
    return <div>Case study not found</div>;
}

return (
    <div className="bg-white">
        {draft && <LivePreviewListener />}
        <HeroSection caseStudy={caseStudy} />
        <CaseStudyBody caseStudy={caseStudy} />
    </div>
);

}

const queryCaseStudyBySlug = cache(async ({ slug }: { slug: string }) => {
const { isEnabled: draft } = await draftMode();
const payload = await getPayload({ config });
const result = await payload.find({
collection: "case-studies",
draft,
limit: 1,
overrideAccess: draft,
pagination: false,
where: {
slug: {
equals: slug,
},
},
});

return result.docs?.[0] || null;

});

lavish karmaBOT
quick valley
#

Hey @grizzled ocean can you provide some more detail on what you're trying to build, if you used one of our templates as a base so that we have more context? Thanks!

grizzled ocean
#

/payload-website-demo/src/app/(frontend)/posts/page.tsx

im trying to recreate this code inside my page.

I have a collection of case-studies and im doing the route for a single case study

grizzled ocean
#

Hmm solved. The issue was overrideAccess , removing that solved my issue