Way too many cookies added to my database
Unanswered
Bombay posted this in #help-forum
BombayOP
Hi all, I co-developed a popular movie trivia app moviegrid.io, and we just deployed a next js version to help with scaling user concurrency. We are very new to nextjs and have only been working on this over the past few months.
I'm tracking users and their guesses with a cookie called "token" set in the browser via middleware. In page.jsx, I look for that cookie and if I can't find it, I then look at the header for "set-cookie" and parse out the cookie the middleware set. I add the result to the db. I'm not sure why so many rows are being added to my userTokens table in my db. Does anyone have any ideas? I've attached screenshots for reference
I'm tracking users and their guesses with a cookie called "token" set in the browser via middleware. In page.jsx, I look for that cookie and if I can't find it, I then look at the header for "set-cookie" and parse out the cookie the middleware set. I add the result to the db. I'm not sure why so many rows are being added to my userTokens table in my db. Does anyone have any ideas? I've attached screenshots for reference
2 Replies
I'm sorry I cant really help, but I would like to follow the thread.
One piece of advice I could give is:
In the code that has
When I think of the problem, I think I would've implemented that using localStorage.
I'm curious, and if you dont mind me asking, why did you choose to store data in cookies instead of localStorage?
One piece of advice I could give is:
In the code that has
if (token) you can remove the second if if (!token) if you return at the end of the first if. if (token) {
// ...
return;
}
token = headers.get() // ... When I think of the problem, I think I would've implemented that using localStorage.
I'm curious, and if you dont mind me asking, why did you choose to store data in cookies instead of localStorage?
@Noronha I'm sorry I cant really help, but I would like to follow the thread.
One piece of advice I could give is:
In the code that has`if (token)` you can remove the second if `if (!token)` if you return at the end of the first if.
if (token) {
// ...
return;
}
token = headers.get() // ...
When I think of the problem, I think I would've implemented that using localStorage.
I'm curious, and if you dont mind me asking, why did you choose to store data in cookies instead of localStorage?
BombayOP
When I originally set this up I wanted to keep most of my components and pages client side, so the ability to read cookies in a server component was helpful. I think I may have to start using localStorage and only use cookies as a fall back