[PR #6666] [CLOSED] feat: electron integration #23712

Closed
opened 2026-04-15 21:55:47 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6666
Author: @jslno
Created: 12/10/2025
Status: Closed

Base: canaryHead: 12-10-2025/electron


📝 Commits (10+)

📊 Changes

18 files changed (+6706 additions, -4275 deletions)

View changed files

📝 docs/components/icons.tsx (+15 -0)
📝 docs/components/sidebar-content.tsx (+6 -0)
docs/content/docs/integrations/electron.mdx (+676 -0)
📝 knip.jsonc (+7 -0)
packages/electron/README.md (+125 -0)
packages/electron/package.json (+95 -0)
packages/electron/src/authenticate.ts (+90 -0)
packages/electron/src/client.ts (+300 -0)
packages/electron/src/cookies.ts (+153 -0)
packages/electron/src/index.ts (+333 -0)
packages/electron/src/proxy.ts (+79 -0)
packages/electron/src/setup-main.ts (+231 -0)
packages/electron/src/types.ts (+82 -0)
packages/electron/test/electron.test.ts (+759 -0)
packages/electron/tsconfig.json (+15 -0)
packages/electron/tsdown.config.ts (+14 -0)
packages/electron/vitest.config.ts (+3 -0)
📝 pnpm-lock.yaml (+3723 -4275)

📄 Description

Summary by cubic

Adds first-class Electron integration for Better Auth with a server plugin, client utilities, deep link handling, PKCE-protected token exchange, secure cookie storage, and IPC bridges/events for smooth sign-in, sign-out, error reporting, and session management in Electron apps.

  • New Features

    • New package: @better-auth/electron (server plugin + client helpers + proxy client).
    • Deep-link scheme registration and callback handling; PKCE token exchange at POST /electron/token.
    • Secure cookie/session storage via Electron safeStorage (works with electron-store); cookie change detection to avoid unnecessary refetches.
    • IPC bridges for requestAuth and signOut, plus onAuthenticated and onAuthError events between main/preload and renderer.
    • CSP setup and trusted-origin handling to satisfy server origin checks.
    • Proxy client to auto-redirect web callbacks to the custom scheme using a temporary redirect cookie.
    • Optional custom client ID for the Electron client.
  • Migration

    • Install better-auth, @better-auth/electron, and electron-store.
    • Enable the electron() plugin in Better Auth and add your scheme origin to trustedOrigins (e.g., com.example.app:/).
    • Configure electronClient with protocol scheme (reverse DNS), redirectURL, and a Storage adapter (electron-store).
    • In main: register the protocol scheme, set it as the default protocol client, and set up IPC and CSP.
    • In preload: call setupIPC() to expose requestAuth, signOut, onAuthenticated, and onAuthError to the renderer.
    • In the web callback route: add electronProxyClient(...) to your web auth client to auto-redirect to your app via the custom scheme.

Written for commit 5ae72e3b43. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6666 **Author:** [@jslno](https://github.com/jslno) **Created:** 12/10/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `12-10-2025/electron` --- ### 📝 Commits (10+) - [`ae3f0a1`](https://github.com/better-auth/better-auth/commit/ae3f0a13f0b38e135f03f7558a8ff61ca90a9939) stash - [`902562c`](https://github.com/better-auth/better-auth/commit/902562c1ecf90404bb99802158d128c10e04f208) chore: fix linting - [`ef2d83e`](https://github.com/better-auth/better-auth/commit/ef2d83ebd5b5990843ca3721ceb78c1045eb5e45) chore: cleanup - [`c663355`](https://github.com/better-auth/better-auth/commit/c6633557063e7fde6411768cf19c1c884626a9a2) feat: handle errors - [`62b276e`](https://github.com/better-auth/better-auth/commit/62b276eaaf4911f5983a368f7940115c5da312ec) Merge branch 'canary' of https://github.com/better-auth/better-auth into 12-10-2025/electron - [`c575352`](https://github.com/better-auth/better-auth/commit/c575352e291790c9f8597a4a2933832c84acf664) chore: add tests - [`6eb04a4`](https://github.com/better-auth/better-auth/commit/6eb04a49598ccfb8740e6fb3b9237ddd81f3307d) chore: update tests & fix linting - [`735fdfb`](https://github.com/better-auth/better-auth/commit/735fdfba699809ddbf90b1c44157c71839aa3ae8) chore: fix deps - [`f786e3e`](https://github.com/better-auth/better-auth/commit/f786e3e0d2f596d35c828005778577bab1f59b5c) feat: sign-out bridge - [`ac86ffd`](https://github.com/better-auth/better-auth/commit/ac86ffd2f90e536da0425f4bf1e7d567a24d4969) chore: minor improvements & fixes ### 📊 Changes **18 files changed** (+6706 additions, -4275 deletions) <details> <summary>View changed files</summary> 📝 `docs/components/icons.tsx` (+15 -0) 📝 `docs/components/sidebar-content.tsx` (+6 -0) ➕ `docs/content/docs/integrations/electron.mdx` (+676 -0) 📝 `knip.jsonc` (+7 -0) ➕ `packages/electron/README.md` (+125 -0) ➕ `packages/electron/package.json` (+95 -0) ➕ `packages/electron/src/authenticate.ts` (+90 -0) ➕ `packages/electron/src/client.ts` (+300 -0) ➕ `packages/electron/src/cookies.ts` (+153 -0) ➕ `packages/electron/src/index.ts` (+333 -0) ➕ `packages/electron/src/proxy.ts` (+79 -0) ➕ `packages/electron/src/setup-main.ts` (+231 -0) ➕ `packages/electron/src/types.ts` (+82 -0) ➕ `packages/electron/test/electron.test.ts` (+759 -0) ➕ `packages/electron/tsconfig.json` (+15 -0) ➕ `packages/electron/tsdown.config.ts` (+14 -0) ➕ `packages/electron/vitest.config.ts` (+3 -0) 📝 `pnpm-lock.yaml` (+3723 -4275) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds first-class Electron integration for Better Auth with a server plugin, client utilities, deep link handling, PKCE-protected token exchange, secure cookie storage, and IPC bridges/events for smooth sign-in, sign-out, error reporting, and session management in Electron apps. - **New Features** - New package: @better-auth/electron (server plugin + client helpers + proxy client). - Deep-link scheme registration and callback handling; PKCE token exchange at POST /electron/token. - Secure cookie/session storage via Electron safeStorage (works with electron-store); cookie change detection to avoid unnecessary refetches. - IPC bridges for requestAuth and signOut, plus onAuthenticated and onAuthError events between main/preload and renderer. - CSP setup and trusted-origin handling to satisfy server origin checks. - Proxy client to auto-redirect web callbacks to the custom scheme using a temporary redirect cookie. - Optional custom client ID for the Electron client. - **Migration** - Install better-auth, @better-auth/electron, and electron-store. - Enable the electron() plugin in Better Auth and add your scheme origin to trustedOrigins (e.g., com.example.app:/). - Configure electronClient with protocol scheme (reverse DNS), redirectURL, and a Storage adapter (electron-store). - In main: register the protocol scheme, set it as the default protocol client, and set up IPC and CSP. - In preload: call setupIPC() to expose requestAuth, signOut, onAuthenticated, and onAuthError to the renderer. - In the web callback route: add electronProxyClient(...) to your web auth client to auto-redirect to your app via the custom scheme. <sup>Written for commit 5ae72e3b43385144835b5170cbe6fe2929157d31. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 21:55:47 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#23712