[PR #7976] [MERGED] feat(electron): allow manual token exchange & add sanitizeUser option #24563

Closed
opened 2026-04-15 22:26:04 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7976
Author: @jslno
Created: 2/15/2026
Status: Merged
Merged: 2/17/2026
Merged by: @Bekacru

Base: canaryHead: 02-14-2026/electron-manual-token-exchange


📝 Commits (10+)

  • 096d53c feat(electron): allow exchanging authorization code manually & add sanitizeUser option
  • 4801238 chore: handle errors gracefully
  • 712987e chore: cleanup
  • c4fd115 Merge remote-tracking branch 'upstream/canary' into 02-14-2026/electron-manual-token-exchange
  • 71f2eac chore: fix linting
  • 61cb3b0 chore: update demo
  • 215378c chore: update docs
  • b1d3c4f chore: cleanup
  • a8417bd chore: update
  • 534cdd8 chore: update tests

📊 Changes

16 files changed (+1132 additions, -254 deletions)

View changed files

📝 demo/electron/src/renderer/src/components/request-auth.tsx (+225 -127)
demo/electron/src/renderer/src/components/ui/input.tsx (+21 -0)
📝 demo/electron/src/renderer/src/components/user-provider.tsx (+4 -0)
📝 demo/nextjs/app/(auth)/sign-in/_components/electron.tsx (+78 -1)
📝 demo/nextjs/components/providers.tsx (+20 -0)
📝 docs/content/docs/integrations/electron.mdx (+82 -0)
📝 packages/electron/src/authenticate.ts (+45 -22)
📝 packages/electron/src/browser.ts (+52 -22)
📝 packages/electron/src/client.ts (+42 -7)
📝 packages/electron/src/index.ts (+11 -5)
📝 packages/electron/src/preload.ts (+25 -12)
📝 packages/electron/src/proxy.ts (+16 -6)
📝 packages/electron/src/routes.ts (+13 -5)
📝 packages/electron/src/types/client.ts (+14 -1)
📝 packages/electron/src/types/index.ts (+2 -1)
📝 packages/electron/test/electron.test.ts (+482 -45)

📄 Description

Summary by cubic

Adds manual authorization code exchange to the Electron client and a sanitizeUser option to filter user data before it reaches the renderer. Adds a deep-link fallback by returning electron_authorization_code and a proxy helper to surface it in the web UI.

  • New Features

    • Introduced electronClient.authenticate({ token, fetchOptions? }) for the main process; broadcasts "authenticated" and is exposed via IPC (better-auth:authenticate) and preload (window.authenticate).
    • requestAuth now only opens the browser; deep links call authenticate({ fetchOptions: { throw: true } }).
    • Added ElectronClientOptions.sanitizeUser (supports async); applied to authenticated events, user-updated broadcasts, and getUser IPC responses.
    • Server returns electron_authorization_code on sign-up and transfer; handleTransfer returns a code or null. Proxy exposes authClient.electron.getAuthorizationCode() to read the code from cookies.
    • Demos: manual code entry in Electron (auto-exchange at 32 chars), web UI shows the code with copy-to-clipboard (toast and transfer flow), and the renderer logs auth errors via onAuthError.
  • Migration

    • After requestAuth, exchange the code with client.authenticate({ token, fetchOptions? }) in the main process or via preload (window.authenticate).
    • Update any flows that relied on requestAuth returning a URL.
    • Optionally set sanitizeUser in ElectronClientOptions to strip sensitive fields before sending to the renderer.

Written for commit 81d3d971aa. 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/7976 **Author:** [@jslno](https://github.com/jslno) **Created:** 2/15/2026 **Status:** ✅ Merged **Merged:** 2/17/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `02-14-2026/electron-manual-token-exchange` --- ### 📝 Commits (10+) - [`096d53c`](https://github.com/better-auth/better-auth/commit/096d53c00cf72df920e1656942f1869bcb0a6868) feat(electron): allow exchanging authorization code manually & add `sanitizeUser` option - [`4801238`](https://github.com/better-auth/better-auth/commit/4801238980db5cb03e0d6f10df45b6c77e8b5b88) chore: handle errors gracefully - [`712987e`](https://github.com/better-auth/better-auth/commit/712987ea2f91ed0cac63a6ef1a86ba26efd02b81) chore: cleanup - [`c4fd115`](https://github.com/better-auth/better-auth/commit/c4fd115de63a3a1c543cf95803d3e1396caae9d3) Merge remote-tracking branch 'upstream/canary' into 02-14-2026/electron-manual-token-exchange - [`71f2eac`](https://github.com/better-auth/better-auth/commit/71f2eac867cd377e0e269982feaea5941668c074) chore: fix linting - [`61cb3b0`](https://github.com/better-auth/better-auth/commit/61cb3b0c830cdb61d3db48effa2dcd123329ec3b) chore: update demo - [`215378c`](https://github.com/better-auth/better-auth/commit/215378c7146d40759eef877e30b89040b991b2a6) chore: update docs - [`b1d3c4f`](https://github.com/better-auth/better-auth/commit/b1d3c4fd57441eac1ad5433e58387b08be4d0f95) chore: cleanup - [`a8417bd`](https://github.com/better-auth/better-auth/commit/a8417bd702f5e10188a90b06ab303921c72111e2) chore: update - [`534cdd8`](https://github.com/better-auth/better-auth/commit/534cdd8c3c00e404c75574fff1aa4b605431df44) chore: update tests ### 📊 Changes **16 files changed** (+1132 additions, -254 deletions) <details> <summary>View changed files</summary> 📝 `demo/electron/src/renderer/src/components/request-auth.tsx` (+225 -127) ➕ `demo/electron/src/renderer/src/components/ui/input.tsx` (+21 -0) 📝 `demo/electron/src/renderer/src/components/user-provider.tsx` (+4 -0) 📝 `demo/nextjs/app/(auth)/sign-in/_components/electron.tsx` (+78 -1) 📝 `demo/nextjs/components/providers.tsx` (+20 -0) 📝 `docs/content/docs/integrations/electron.mdx` (+82 -0) 📝 `packages/electron/src/authenticate.ts` (+45 -22) 📝 `packages/electron/src/browser.ts` (+52 -22) 📝 `packages/electron/src/client.ts` (+42 -7) 📝 `packages/electron/src/index.ts` (+11 -5) 📝 `packages/electron/src/preload.ts` (+25 -12) 📝 `packages/electron/src/proxy.ts` (+16 -6) 📝 `packages/electron/src/routes.ts` (+13 -5) 📝 `packages/electron/src/types/client.ts` (+14 -1) 📝 `packages/electron/src/types/index.ts` (+2 -1) 📝 `packages/electron/test/electron.test.ts` (+482 -45) </details> ### 📄 Description <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds manual authorization code exchange to the Electron client and a sanitizeUser option to filter user data before it reaches the renderer. Adds a deep-link fallback by returning electron_authorization_code and a proxy helper to surface it in the web UI. - **New Features** - Introduced electronClient.authenticate({ token, fetchOptions? }) for the main process; broadcasts "authenticated" and is exposed via IPC (better-auth:authenticate) and preload (window.authenticate). - requestAuth now only opens the browser; deep links call authenticate({ fetchOptions: { throw: true } }). - Added ElectronClientOptions.sanitizeUser (supports async); applied to authenticated events, user-updated broadcasts, and getUser IPC responses. - Server returns electron_authorization_code on sign-up and transfer; handleTransfer returns a code or null. Proxy exposes authClient.electron.getAuthorizationCode() to read the code from cookies. - Demos: manual code entry in Electron (auto-exchange at 32 chars), web UI shows the code with copy-to-clipboard (toast and transfer flow), and the renderer logs auth errors via onAuthError. - **Migration** - After requestAuth, exchange the code with client.authenticate({ token, fetchOptions? }) in the main process or via preload (window.authenticate). - Update any flows that relied on requestAuth returning a URL. - Optionally set sanitizeUser in ElectronClientOptions to strip sensitive fields before sending to the renderer. <sup>Written for commit 81d3d971aaa3f1fc492c13a5437d48b07ee65d24. 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 22:26:04 -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#24563