Setting cookie in backend and getting it in frontend
Unanswered
African Slender-snouted Crocodil… posted this in #help-forum
Original message was deleted.
60 Replies
European sprat
Create a minimal reproduction and I'll have a look
European sprat
what route or page do i hit to show the issue?
i'm not seeing a token set anywhere, is it assumed that they are set before this route is hit?
European sprat
ok so i see the cookies being logged, what's the issue?
how do i test the frontend
next time make a proper minimal repro when asked and have basic instructions on how to run the test it isn't immediately obvious
im still under the impression that because path isn't set to root, it is not being sent: https://nextjs.org/docs/app/api-reference/functions/cookies#cookiessetname-value-options and https://github.com/Revaycolizer/next-backend/blob/main/app/api/adlogin/route.ts#L44 (but if you have tested that, then follow Jarrah's advice to get help)
how does one start this project, do we have to build it and run it ourselves
is there anything that other then
nextauth_secret that needs to be created to run?i read your readme and that was mentioned... so can you provide instructions then...
(sorry for being a pain, Jarrah might understand this better though)
ok, can you spend some time creating the minimal reproduction and then come back to us 🙂
European sprat
i spent 20 min trying to figure it out
im tanking about the one that is using cookies().set
are we saying "userToken" works but not "adminToken"?
ok, so if you go to your browser and its cookie settings, they both are there right?
and when you go to the other route, check the headers sent there (are those containing the cookies) - browser side
what browser?
go to network in dev tools
reload page
click on first one
go to headers
go to request headers
check the "cookie" value
umm do you need images:
https://mkyong.com/computer-tips/how-to-view-http-headers-in-google-chrome/ and still scroll untill you see cookie in request section
https://mkyong.com/computer-tips/how-to-view-http-headers-in-google-chrome/ and still scroll untill you see cookie in request section
so to check so far, is this the values you are expecting
ok good
Original message was deleted
and your saying this is the route that you just accessed?
and you say that authorization is none
so, your browser send headers but cookiestore doesn't see it
hmm, can you try and console.log req.headers
anywhere in that route
@African Slender-snouted Crocodile how did that go?
umm try with
new Headers(request.headers) (i thought you could just not need it, but apparently no)yeah
Original message was deleted
...and thats only occurring when you try and get the headers (like without my code, it was working?)
well, thats a whole another issue then (as i was trying to help with the cookies not this error)
and um well i have other things to do, so enjoy i guess..?
idk then, if the browser is sending it and the route can't see it, then you either have some weird code, or found a bug
idk middle wires and such (code that is run in every request before your handler gets the request)
if you consume it with a cookie name that isn't set is it also null
also can you try updating to the latest nextjs version (and potentially the canary one)
then, id try to make a simpler code that has this result and then submit a bug report (once you are sure that you have done everything correctly)
and the part of a small reproduction sample now
like either make a new project using the same code that is broken, or remove everything else that isn't needed to produce the error (also includes deps)
just things that you arn't mentioning in the said bug report
(and that isn't required for the mentioned things)
yeah
European sprat
a minimal reproduction is to setup a fresh next app that only includes the specific code that you are trying to use which does not behave the way you expect it to. a person should be able to pull the code, install packages and run it then navigate to a page you specific and clearly see what the issue is
do you need prisma for this error?
or can you get away with just the contents of the cookie
Original message was deleted
so, could you remove it and place a console.log that says user would be created here
Original message was deleted
like remember make it as minimal as possible
if you would say in the bug report that x routes arn't working, show them all
but i think you only need one for setting and another for getting the cookie
Original message was deleted
so without prisma, there is no error?
Original message was deleted
so remove the part with prisma and keep the rest of the code the same (and just statically do values)
also look at the steps for bug rep: https://github.com/vercel/next.js/issues/new?assignees=&labels=template%3A+bug&projects=&template=1.bug_report.yml as they may help you to understand whats needed
um i don't have much time to look at this again, but it could be due to some config that you have... so good luck ig...
try going to the save version as that user