Skip to content

Commit

Permalink
Merge pull request #123 from kinde-oss/peter/fix/logout-across-subdomain
Browse files Browse the repository at this point in the history
fix: removing cookies across domains
  • Loading branch information
peterphanouvong authored Feb 8, 2024
2 parents 54ec11b + 566c3f4 commit bc20c1f
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/session/sessionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export const appRouterSessionManager = (cookieStore) => ({
* @returns {Promise<void>}
*/
removeSessionItem: (itemKey) => {
cookieStore.delete(itemKey);
cookieStore.set(itemKey, '', {
domain: config.cookieDomain ? config.cookieDomain : undefined,
maxAge: 0
});
},
/**
* @returns {Promise<void>}
Expand All @@ -76,8 +79,14 @@ export const appRouterSessionManager = (cookieStore) => ({
'access_token_payload',
'access_token',
'user',
'refresh_token'
].forEach((name) => cookieStore.delete(name));
'refresh_token',
'post_login_redirect_url'
].forEach((name) =>
cookieStore.set(name, '', {
domain: config.cookieDomain ? config.cookieDomain : undefined,
maxAge: 0
})
);
}
});

Expand Down Expand Up @@ -140,8 +149,11 @@ export const pageRouterSessionManager = (req, res) => {
*/
removeSessionItem: (itemKey) => {
res?.setHeader('Set-Cookie', [
cookie.serialize(itemKey, '', {path: '/', maxAge: -1}),
cookie.serialize(itemKey, '', {maxAge: -1})
cookie.serialize(itemKey, '', {
domain: config.cookieDomain ? config.cookieDomain : undefined,
path: '/',
maxAge: -1
})
]);
},
destroySession: () => {
Expand All @@ -152,16 +164,15 @@ export const pageRouterSessionManager = (req, res) => {
'access_token_payload',
'access_token',
'user',
'refresh_token'
].map((name) => cookie.serialize(name, '', {path: '/', maxAge: -1})),
...[
'id_token_payload',
'id_token',
'access_token_payload',
'access_token',
'user',
'refresh_token'
].map((name) => cookie.serialize(name, '', {maxAge: -1}))
'refresh_token',
'post_login_redirect_url'
].map((name) =>
cookie.serialize(name, '', {
domain: config.cookieDomain ? config.cookieDomain : undefined,
path: '/',
maxAge: -1
})
)
]);
}
};
Expand Down

0 comments on commit bc20c1f

Please sign in to comment.