-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom path for preview mode cookies #38313
Conversation
...(options.path !== undefined | ||
? ({ path: options.path } as CookieSerializeOptions) | ||
: undefined), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also considering doing something like
...(options.path !== undefined | |
? ({ path: options.path } as CookieSerializeOptions) | |
: undefined), | |
...(options.path !== undefined | |
? ({ path: options.path || '/' } as CookieSerializeOptions) | |
: undefined), |
but I found out that there's a normalization function for the cookie serialize function params.
Also, I though about refactoring this maxAge
and path
props to have a single object like
...(options.path !== undefined | |
? ({ path: options.path } as CookieSerializeOptions) | |
: undefined), | |
...({ path: options.path , maxAge: options.maxAge }), |
But when path
or maxAge
is empty, we'd be passing { path: undefined, maxAge: undefined }
instead of { }
. Those are actually different, and I'm not certain how the options
object properties are treated down the chain
...(options.maxAge !== undefined | ||
? ({ maxAge: options.maxAge } as CookieSerializeOptions) | ||
: undefined), | ||
...(options.path !== undefined | ||
? ({ path: options.path } as CookieSerializeOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While checking CookieSerializeOptions
type definitions, I noticed that it'd be good to update it to v0.5.1 to get the latest (and more complete definitions). /@types/cookie/0.5.1
has correct links to https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.4 which is way more helpful to understand how this path
and maxAge
behave. I thought about doing it in the same PR, but I think it's rather better to keep deps updates isolated
@@ -461,6 +461,7 @@ function setPreviewData<T>( | |||
data: object | string, // TODO: strict runtime type checking | |||
options: { | |||
maxAge?: number | |||
path?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it'd be good enough to just accept raw path
as string
in this setPreviewData
function here without extra parsing/validation on it because developers would control the setPreviewData
call and its parameters, just like they do with redirects inside the preview
API endpoint. The security concerns around path
remain the same though - https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.2.4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, being able to enable preview mode for specific paths sounds like a good addition, thanks for the PR!
Fixes #38312
Bug
fixes #number
contributing.md
Feature
fixes #number
contributing.md
Documentation / Examples
pnpm lint