Skip to content

Commit

Permalink
fix: parse auth cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban committed Dec 19, 2024
1 parent 8a666e5 commit 626db9a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions apps/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@openpanel/web": "1.0.1",
"@sentry/electron": "5.7.0",
"builder-util-runtime": "9.2.10",
"cookie-es": "^1.2.2",
"dompurify": "~3.2.2",
"electron-context-menu": "4.0.4",
"electron-log": "5.2.4",
Expand Down
23 changes: 14 additions & 9 deletions apps/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { callWindowExpose } from "@follow/shared/bridge"
import { APP_PROTOCOL } from "@follow/shared/constants"
import { env } from "@follow/shared/env"
import { imageRefererMatches, selfRefererMatches } from "@follow/shared/image"
import { parse } from "cookie-es"
import { app, BrowserWindow, session } from "electron"
import type { Cookie } from "electron/main"
import squirrelStartup from "electron-squirrel-startup"
Expand Down Expand Up @@ -194,16 +195,20 @@ function bootstrap() {

if (ck && apiURL) {
setBetterAuthSessionCookie(ck)
const cookie = atob(ck)
mainWindow.webContents.session.cookies.set({
url: apiURL,
name: cookie.split("=")[0],
value: cookie.split("=")[1],
secure: true,
httpOnly: true,
domain: new URL(apiURL).hostname,
sameSite: "no_restriction",
const cookie = parse(atob(ck))
Object.keys(cookie).forEach((name) => {
const value = cookie[name]
mainWindow.webContents.session.cookies.set({
url: apiURL,
name,
value,
secure: true,
httpOnly: true,
domain: new URL(apiURL).hostname,
sameSite: "no_restriction",
})
})

userId && (await callWindowExpose(mainWindow).clearIfLoginOtherAccount(userId))
mainWindow.reload()

Expand Down
22 changes: 15 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 626db9a

Please sign in to comment.