#Error: Invariant: cookies() expects to have requestAsyncStorage, none available.

26 messages · Page 1 of 1 (latest)

plush kayak
#

This error seems to be occuring when called inside generateStaticParams(). I had used the same function in a normal page component, but this particular dynamic route page seems to have a problem.

patent yarrowBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

amber mountain
plush kayak
spiral nexus
noble chasm
#

no import?

spiral nexus
#

which meant opting into request-time dynamic SSR

plush kayak
#

Context:
I want to make an API request to fetch a list of data from my backend, that data is supposed to passed into generateStaticParams (dynamic segments). This request can only be made with an auth token (stored in cookies).

#

Is using generateStaticParams in this context the correct way?

spiral nexus
#

no

#

because with generateStaticParams you are generating page at build time. In build time, no user means no request, no request means no cookie

#

what are you trying to achieve?

plush kayak
#

I'm trying to create dynamic routes with authenticated users. Each user has their own unique data (which also means the slug in the route will always be different for each user)

spiral nexus
#

ahh which mean you can't possibly check that at build time right? then you can't use generateStaticParams

plush kayak
#

Hmm yeah

spiral nexus
#

you need to check the "unique data" in the [id] slug and see if they had access to id

#

if not then send them to notFound()

#

this is the SSR way, processing data at request-time

plush kayak
#

So I just have to not use generateStaticParams?

spiral nexus
#

yeah

plush kayak
#

I just have to do this?

spiral nexus
#
export async function isAllowed(slug: string){
  try { 
    await getAuthData(slug) // <-- also has cookies() in there to check against user cookies which are going to be sent to the db/backend
  } catch(error) {
    notFound()
  }
}
#

yeah

plush kayak
#

Ahh ok

spiral nexus
#

if not allowed then call notFound() from next/navigation

plush kayak
#

Thanks so much! I know what to do now 🙂