Skip to content

Commit

Permalink
支持 samesite=none cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
hotlong committed Dec 9, 2024
1 parent 0796576 commit afc8cf7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ STEEDOS_AMIS_URL=

# 资产包
STEEDOS_UNPKG_URL=
STEEDOS_PUBLIC_PAGE_ASSETURLS=
STEEDOS_PUBLIC_PAGE_ASSETURLS=

STEEDOS_AUTH_COOKIES_USE_SAMESITE=None
7 changes: 5 additions & 2 deletions packages/utils/src/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function getSubdomain(host) {
}

export function setCookie(req, res, name, value, options = {domain: null, maxAge: 0, httpOnly: true, overwrite: true}) {
const cookies = new Cookies(req, res);
const cookies = new Cookies(req, res, {secure: true});
const host = req.headers.host;
if(host && useSubdomainCookies && psl.isValid(host)){
const domain = getSubdomain(host);
Expand All @@ -23,13 +23,16 @@ export function setCookie(req, res, name, value, options = {domain: null, maxAge

if(sameSite){
(options as any).sameSite = sameSite;
if (sameSite === 'None') {
(options as any).secure = true;
}
}

cookies.set(name, value, options);
}

export function clearCookie(req, res, name, options = {domain: null, maxAge: 0, httpOnly: true, overwrite: true}) {
const cookies = new Cookies(req, res);
const cookies = new Cookies(req, res, {secure: true});
const host = req.headers.host;
if(host && useSubdomainCookies && psl.isValid(host)){
const domain = getSubdomain(host);
Expand Down

0 comments on commit afc8cf7

Please sign in to comment.