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