Next.js Discord

Discord Forum

Iron-Session issue while using server component

Unanswered
Mini Satin posted this in #help-forum
Open in Discord
Mini SatinOP
Hey there I am using iron-session@^8.0.2 with my nextjs@14.2.5

As I showed in screenshot I am trying to fetch data in my server side page by calling one of api which check if user is authenticated or not and if user is authenticated it return data but when I hit URL for this page my route shows empty iron session data. Is there any other way to fetch data or am I doing something wrong .!?

8 Replies

shouldn't you await sessionData()?
in getBlogs()
Mini SatinOP
@D Trombett yeah thanks
@D Trombett I am fetch data through route I am querious can I use my mongoose model directly inside this getBlogs function like it is safe to do that.??
if it's a server component you're safe, the code will be executed only on the server
I see that you're using a NEXT_PUBLIC env variable tho
consider that if you use NEXT_PUBLIC_ the variable will be exposed to the client
Mini SatinOP
hmm thanks for the help I guess because I was sending api request from my server(which does not have cookie in it) and then api tries to get cookie cause this error.