How to Send OTP in an Electron Desktop App (2026)
Electron OTP tutorial using StartMessaging. Calls a thin remote backend (never embed API keys in the desktop bundle), uses safeStorage for the session token.
StartMessaging Team
Engineering
Electron desktop apps need OTP login like any other client — but the key rule is: API keys do not live in the desktop bundle. Always proxy through a backend.
Security First
- Backend holds SM_API_KEY.
- Electron app calls backend over HTTPS.
- Use
contextIsolation: trueandnodeIntegration: false.
Main Process — Network Bridge
// src/main/handlers.ts
import { ipcMain, net } from 'electron';
ipcMain.handle('auth:send-otp', async (_e, phone: string) => {
const r = await net.fetch('https://your-backend.example.com/auth/send-otp', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ phoneNumber: phone }),
});
return r.json();
});Preload Bridge
// src/preload/index.ts
import { contextBridge, ipcRenderer } from 'electron';
contextBridge.exposeInMainWorld('auth', {
sendOtp: (phone: string) => ipcRenderer.invoke('auth:send-otp', phone),
verifyOtp: (requestId: string, code: string) =>
ipcRenderer.invoke('auth:verify-otp', { requestId, code }),
});Renderer UI
// React component
const send = async () => {
const r = await window.auth.sendOtp(phone);
setRequestId(r.requestId);
};
const verify = async () => {
await window.auth.verifyOtp(requestId, code);
};Session via safeStorage
import { safeStorage } from 'electron';
const buf = safeStorage.encryptString(token);
// store buf in user data dirFAQ
For the backend half see our Express guide.
Related Articles
Step-by-step Node.js tutorial to send and verify OTP via SMS using the StartMessaging API. Includes fetch examples, error handling, and verification flow.
Production-ready Express.js OTP guide using StartMessaging. Covers send, verify, idempotency, rate-limit middleware, error mapping and a session-based verification flow.
React Native OTP tutorial using Expo and StartMessaging. Includes secure storage, auto-fill (Android SMS Retriever / iOS keychain), and a Node backend pattern.
Ready to Send OTPs?
Integrate StartMessaging in 5 minutes. No DLT registration required.