Skip to main content
@glinr/theauth-electron provides secure auth for Electron desktop apps with encrypted token storage, OAuth popup windows, and an IPC bridge for renderer-to-main communication.

Install

Setup (main process)

Create a storage adapter backed by Electron’s safeStorage API, then expose it to the renderer over IPC:
Open the OAuth popup window from a main-process IPC handler:

Usage (renderer)

Wrap your renderer’s React tree in ElectronTheAuthProvider. Pass a SecureStorage adapter, either createIpcStorage() (delegates to the main process over IPC, recommended with contextIsolation) or createElectronStorage() directly if Node integration is enabled:
Read session state and call auth actions with useElectronTheAuthContext:
signIn and signUp call the username routes by default. Pass emailPassword to ElectronTheAuthProvider to call the core email and password routes (/auth/email/sign-in and /auth/email/sign-up, body field email) that the server serves when it sets the emailPassword config, see Email and password. With verification on (the default) signUp resolves to data.verificationRequired === true and signs nobody in, and a sign-in before verification fails with code: "EMAIL_NOT_VERIFIED". For OAuth providers, trigger openOAuthWindow from the main process (see above), then call refresh() from the renderer once the window resolves to pick up the new session.

Features

Token storage uses Electron’s safeStorage.encryptString() which uses the OS keychain (Keychain on macOS, DPAPI on Windows, Secret Service on Linux). If encryption is unavailable, createElectronStorage falls back to plaintext and logs a warning.
Last modified on October 19, 2026