Common cookies among all requests in Remix application #9676
Unanswered
DarthLegiON
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I'm not new to Web developing but new to Remix. And I have an intention: making a website, I want to identify users using
Device-Id
cookie. This cookie must set in every request starting from first opening the site by new user that doesn't have the cookie yet. Also, the cookie must be sent to Sentry on any issue happened on the server, and to any API request sent both from server and client. The cookie should be generated as UUID.It can be done if cookie already present in the request: I just need to extract it from request and use in handleRequest (to set Sentry context) and in loaders (to inject in the API calls), and then use
Cookie.get
on client side to usee the cookie in browser. But there is a problem to create the cookie and make it work at first time. I found a way to set the cookie inhandleRequest
(entry.server.ts
) if it's not present, but it won't be used by any loaders before they're starting on their own beforehandleRequest
and because request isn't shared among them. Also I couldn't find a way to somehow share the cookie right after its generation.The easiest way in backend frameworks is using middlewares and singleton classes that contain already generated cookie among the project. But I haven't found the middleware functionality in Remix, only its RFC. In this article answers suggest to run the same code on loader start, but if there are several loaders, each API request will have different ids. And loader cannot set response headers too.
Please suggest me the most preferrable solution to my task. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions