fix: force reset callbackurl cookie in electron (#4199)
This commit is contained in:
@@ -7,6 +7,7 @@ import { logger } from './logger';
|
|||||||
import {
|
import {
|
||||||
handleOpenUrlInHiddenWindow,
|
handleOpenUrlInHiddenWindow,
|
||||||
mainWindowOrigin,
|
mainWindowOrigin,
|
||||||
|
removeCookie,
|
||||||
restoreOrCreateWindow,
|
restoreOrCreateWindow,
|
||||||
setCookie,
|
setCookie,
|
||||||
} from './main-window';
|
} from './main-window';
|
||||||
@@ -92,11 +93,12 @@ async function handleOauthJwt(url: string) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// force reset next-auth.callback-url
|
// force reset next-auth.callback-url
|
||||||
await setCookie({
|
// there could be incorrect callback-url in cookie that will cause auth failure
|
||||||
url: CLOUD_BASE_URL,
|
// so we need to reset it to empty to mitigate this issue
|
||||||
httpOnly: true,
|
await removeCookie(
|
||||||
name: 'next-auth.callback-url',
|
CLOUD_BASE_URL,
|
||||||
});
|
isSecure ? '__Secure-next-auth.callback-url' : 'next-auth.callback-url'
|
||||||
|
);
|
||||||
|
|
||||||
// hacks to refresh auth state in the main window
|
// hacks to refresh auth state in the main window
|
||||||
const window = await handleOpenUrlInHiddenWindow(
|
const window = await handleOpenUrlInHiddenWindow(
|
||||||
|
|||||||
@@ -203,6 +203,11 @@ export async function setCookie(
|
|||||||
await window.webContents.session.cookies.set(details);
|
await window.webContents.session.cookies.set(details);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function removeCookie(url: string, name: string): Promise<void> {
|
||||||
|
const window = await restoreOrCreateWindow();
|
||||||
|
await window.webContents.session.cookies.remove(url, name);
|
||||||
|
}
|
||||||
|
|
||||||
export async function getCookie(url?: string, name?: string) {
|
export async function getCookie(url?: string, name?: string) {
|
||||||
const window = await restoreOrCreateWindow();
|
const window = await restoreOrCreateWindow();
|
||||||
const cookies = await window.webContents.session.cookies.get({
|
const cookies = await window.webContents.session.cookies.get({
|
||||||
|
|||||||
Reference in New Issue
Block a user