Install using bunx shadcn@latest add @remix-utils/rolling-cookie.
bunx shadcn@latest add @remix-utils/rolling-cookie
This depends on zod, and React Router.
zod
Rolling cookies allows you to prolong the expiration of a cookie by updating the expiration date of every cookie.
The rollingCookie function is prepared to be used in entry.server exported function to update the expiration date of a cookie if no loader set it.
rollingCookie
entry.server
For document request you can use it on the handleRequest function:
handleRequest
import { rollingCookie } from "remix-utils/rolling-cookie";import { sessionCookie } from "~/session.server";export default function handleRequest( request: Request, responseStatusCode: number, responseHeaders: Headers, remixContext: EntryContext,) { await rollingCookie(sessionCookie, request, responseHeaders); return isbot(request.headers.get("user-agent")) ? handleBotRequest(request, responseStatusCode, responseHeaders, remixContext) : handleBrowserRequest(request, responseStatusCode, responseHeaders, remixContext);} Copy
import { rollingCookie } from "remix-utils/rolling-cookie";import { sessionCookie } from "~/session.server";export default function handleRequest( request: Request, responseStatusCode: number, responseHeaders: Headers, remixContext: EntryContext,) { await rollingCookie(sessionCookie, request, responseHeaders); return isbot(request.headers.get("user-agent")) ? handleBotRequest(request, responseStatusCode, responseHeaders, remixContext) : handleBrowserRequest(request, responseStatusCode, responseHeaders, remixContext);}
And for data request you can do it on the handleDataRequest function:
handleDataRequest
import { rollingCookie } from "remix-utils/rolling-cookie";export let handleDataRequest: HandleDataRequestFunction = async ( response: Response, { request },) => { let cookieValue = await sessionCookie.parse(responseHeaders.get("set-cookie")); if (!cookieValue) { cookieValue = await sessionCookie.parse(request.headers.get("cookie")); responseHeaders.append("Set-Cookie", await sessionCookie.serialize(cookieValue)); } return response;}; Copy
import { rollingCookie } from "remix-utils/rolling-cookie";export let handleDataRequest: HandleDataRequestFunction = async ( response: Response, { request },) => { let cookieValue = await sessionCookie.parse(responseHeaders.get("set-cookie")); if (!cookieValue) { cookieValue = await sessionCookie.parse(request.headers.get("cookie")); responseHeaders.append("Set-Cookie", await sessionCookie.serialize(cookieValue)); } return response;};
> Read more about rolling cookies in Remix.
Sergio XalambrÃ
Install using
bunx shadcn@latest add @remix-utils/rolling-cookie.This depends on
zod, and React Router.Rolling cookies allows you to prolong the expiration of a cookie by updating the expiration date of every cookie.
The
rollingCookiefunction is prepared to be used inentry.serverexported function to update the expiration date of a cookie if no loader set it.For document request you can use it on the
handleRequestfunction:And for data request you can do it on the
handleDataRequestfunction:> Read more about rolling cookies in Remix.
Author
Sergio XalambrÃ