Skip to content

Commit 4c62373

Browse files
committed
Fix logout when using from inside an iframe
1 parent b12b9e7 commit 4c62373

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/auth.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { revalidatePath, revalidateTag } from 'next/cache';
44
import { cookies, headers } from 'next/headers';
55
import { redirect } from 'next/navigation';
6-
import { WORKOS_COOKIE_DOMAIN, WORKOS_COOKIE_NAME } from './env-variables.js';
6+
import { WORKOS_COOKIE_DOMAIN, WORKOS_COOKIE_NAME, WORKOS_COOKIE_SAMESITE } from './env-variables.js';
77
import { getAuthorizationUrl } from './get-authorization-url.js';
88
import { SwitchToOrganizationOptions, UserInfo } from './interfaces.js';
99
import { refreshSession, withAuth } from './session.js';
@@ -38,8 +38,10 @@ export async function signOut({ returnTo }: { returnTo?: string } = {}) {
3838
} finally {
3939
const nextCookies = await cookies();
4040
const cookieName = WORKOS_COOKIE_NAME || 'wos-session';
41+
const sameSite = WORKOS_COOKIE_SAMESITE || 'lax';
4142
const domain = WORKOS_COOKIE_DOMAIN || /* istanbul ignore next */ undefined;
42-
nextCookies.delete({ name: cookieName, domain, path: '/' });
43+
const secure = sameSite.toLowerCase() === 'none' ? true : undefined;
44+
nextCookies.delete({ name: cookieName, domain, path: '/', sameSite, secure });
4345

4446
if (sessionId) {
4547
redirect(getWorkOS().userManagement.getLogoutUrl({ sessionId, returnTo }));

0 commit comments

Comments
 (0)