Now, every request will have the cookie updated with a new expiration date.
Note
If you set the same cookie in your own loaders or actions, the middleware will detect this and do nothing, so you can use the middleware and set the cookie in your own code without worrying about it.
Install using
bunx shadcn@latest add @remix-utils/middleware-rolling-cookie.This depends on
zod, and React Router.The rolling cookie middleware allows you to prolong the expiration of a cookie by updating the expiration date on every request.
First, create a rolling cookie middleware instance:
Then, add the
rollingCookieMiddlewareto themiddlewarearray in yourapp/root.tsxfile.Now, every request will have the cookie updated with a new expiration date.
If you set the same cookie in your own loaders or actions, the middleware will detect this and do nothing, so you can use the middleware and set the cookie in your own code without worrying about it.
Author
License
Author
Sergio XalambrÃ