Skip to content

Commit

Permalink
Supporting SSR cookie writes by "Set-Cookie" header
Browse files Browse the repository at this point in the history
  • Loading branch information
BierDav authored Aug 16, 2023
1 parent f7d3fd8 commit 84088e1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/storage/src/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,17 @@ export const cookieStorage: StorageWithOptions<CookieOptions> = addClearMethod({
}
: () => document.cookie,
_write: isServer
? (key: string, value: string, options?: CookieOptions) =>
options?.setCookie?.(key, value, options)
? (key: string, value: string, options?: CookieOptions) => {
if (options?.setCookie) {
options?.setCookie?.(key, value, options)
return
}
const eventOrRequest = options?.getRequest?.() || useRequest();
if ("request"! in eventOrRequest || "responseHeaders"! in eventOrRequest)
return
const request = eventOrRequest && ("request" in eventOrRequest ? eventOrRequest.request : eventOrRequest);
const responseHeaders = eventOrRequest && ("responseHeaders" in eventOrRequest ? eventOrRequest.responseHeaders : eventOrRequest);
}
: (key: string, value: string, options?: CookieOptions) => {
document.cookie = `${key}=${value}${serializeCookieOptions(options)}`;
},
Expand Down

0 comments on commit 84088e1

Please sign in to comment.