@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’ssafeStorage API, then expose it to the renderer over IPC:
Usage (renderer)
Wrap your renderer’s React tree inElectronTheAuthProvider. Pass a SecureStorage adapter, either createIpcStorage() (delegates to the main process over IPC, recommended with contextIsolation) or createElectronStorage() directly if Node integration is enabled:
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.