Skip to content

Commit 7fa52f5

Browse files
authored
The signOut method in auth.ts does not delete cookies set with a custom domain. This enables custom domain cookies to be deleted by checking if a custom domain has been set for the cookie. If so, it adds the custom domain to the keys that Nextjs' ResponseCookie's delete method matches against, now finding the cookie and deleting it. (#116)
1 parent cdb0fab commit 7fa52f5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/auth.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { getAuthorizationUrl } from './get-authorization-url.js';
44
import { cookies } from 'next/headers';
55
import { terminateSession } from './session.js';
6-
import { WORKOS_COOKIE_NAME } from './env-variables.js';
6+
import { WORKOS_COOKIE_NAME, WORKOS_COOKIE_DOMAIN } from './env-variables.js';
77

88
async function getSignInUrl({ organizationId }: { organizationId?: string } = {}) {
99
return getAuthorizationUrl({ organizationId, screenHint: 'sign-in' });
@@ -14,8 +14,11 @@ async function getSignUpUrl() {
1414
}
1515

1616
async function signOut() {
17-
const cookieName = WORKOS_COOKIE_NAME || 'wos-session';
18-
cookies().delete(cookieName);
17+
const cookie: { name: string; domain?: string } = {
18+
name: WORKOS_COOKIE_NAME || 'wos-session',
19+
};
20+
if (WORKOS_COOKIE_DOMAIN) cookie.domain = WORKOS_COOKIE_DOMAIN;
21+
cookies().delete(cookie);
1922
await terminateSession();
2023
}
2124

0 commit comments

Comments
 (0)