Next.js Discord

Discord Forum

How can i get the the params id in inside the metadata?

Answered
shadow posted this in #help-forum
Open in Discord

25 Replies

Answer
@Gazami crab check dynamic metadata https://nextjs.org/docs/app/building-your-application/optimizing/metadata#dynamic-metadata
thats what im trying but know im having another problem so if u can help me will be cool

TypeError: Failed to parse URL from /api/media/movie?id=933131
    at getMovie (./lib/utils.ts:97:24)
    at Module.generateMetadata (dashboard/movies/[id]/page.tsx:21:77)
digest: "3621837652"
directly get the data in there
dont make uneccesary round trips
i did that because the api key keeps appering in the network requests
did you put it in .env?
yes
whats the name of the variable?
@aardani whats the name of the variable?
NEXT_PUBLIC_TMDB_API_KEY
remove NEXT_PUBLIC_
and it will make sure it wont be accidentally called in the client
@Gazami crab can you check this code? const id = params.id; const movie = await getMovie({ id });
dont work either im gonna try @aardani suggestion
@aardani dont fetch to your own server
this is an invalid fetch
@aardani remove `NEXT_PUBLIC_`
in the past i tried that but the api key is undefined
probably i shouldnt make request in client components right
yeah
you shouldnt be getting that if you dont want to do the fetch in the client....
or use/expose the key in the client...
make the request in server componets and pass the data via props right
yeah
generateMetadata is a server function though and you just call the db method directly
since
its already in the server...