Skip to content

Commit 94b7d8b

Browse files
authored
Merge pull request #36 from kinde-oss/feat/cookiedomain
feat: add cookie domain to session hooks
2 parents 23be2db + 9febd93 commit 94b7d8b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Next step, create `.env` file:
7575
KINDE_AUDIENCE=your_kinde_api
7676
KINDE_CLIENT_ID=your_kinde_client_id // Please use an application with password method
7777
KINDE_CLIENT_SECRET=your_kinde_client_secret
78+
KINDE_COOKIE_DOMAIN=// domain to assign cookie to
7879
KINDE_ISSUER_URL=https://your_kinde_domain.kinde.com
7980
KINDE_POST_LOGIN_REDIRECT_URL=http://localhost:4173
8081
KINDE_POST_LOGOUT_REDIRECT_URL=http://localhost:4173

src/lib/hooks/sessionHooks.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export async function sessionHooks({ event }: { event: EventHandler }) {
1111
? itemValue
1212
: (JSON.stringify(itemValue) as string),
1313
{
14+
domain: process.env.KINDE_COOKIE_DOMAIN,
1415
path: "/",
1516
secure: process.env.NODE_ENV === "production",
1617
sameSite: "lax",
@@ -40,13 +41,17 @@ export async function sessionHooks({ event }: { event: EventHandler }) {
4041
event.request.removeSessionItem = async (itemKey: string) => {
4142
return event.cookies.delete(`kinde_${itemKey}`, {
4243
path: "/",
44+
domain: process.env.KINDE_COOKIE_DOMAIN,
4345
});
4446
};
4547

4648
event.request.destroySession = async () => {
4749
event.cookies.getAll().forEach((item) => {
4850
if (/^kinde_/.test(item.name)) {
49-
event.cookies.delete(item.name, { path: "/" });
51+
event.cookies.delete(item.name, {
52+
path: "/",
53+
domain: process.env.KINDE_COOKIE_DOMAIN,
54+
});
5055
}
5156
});
5257
return;

0 commit comments

Comments
 (0)