⚡ OTPless Authentication
WhatsApp Magic Link
This is Emacron's separate OTPless message-link flow, not Meta One-Tap or Zero-Tap. The user opens WhatsApp from your app, reviews and sends a pre-filled message, then Emacron verifies the session when the inbound webhook is received. The user does not type OTP digits, but must still send the message.
No OTP digits
Typed by the user
Send required
User action in WhatsApp
Webhook
Confirms the session
How it works
For project-specific authentication, create a WhatsApp OTPless or combined key in Settings → API Keys. Assign a sender, prefilled message, and success reply. Tap and QR links use the same settings. Use the key from your server to create and check sessions, and register approved HTTPS origins for any return URLs.
The session token is encoded as invisible Unicode zero-width characters (ZWJ/ZWNJ) inside the visible message. WhatsApp includes them when the user taps Send. Treat the generated login links as sensitive until the session expires.
Your backend calls /magic-link/init
Returns session_id, wa_link (mobile button), scan_url (desktop QR), and stores your redirect_url.
Frontend shows button (mobile) or QR (desktop)
Detect mobile with navigator.userAgent. Mobile: <a href={wa_link}>. Desktop: <QRCodeSVG value={scan_url} />.
User taps or scans
WhatsApp opens with the pre-filled message that has an invisible verification token embedded in it.
User hits Send
The message with the hidden token arrives in your workspace WhatsApp inbox.
Webhook decodes token
Token is extracted, matched to session, session marked verified. Zero code entered or seen.
Poll returns verified: true
Your backend checks the verified phone, completes its own application login, and can send the user to the approved return URL.
Authentication
All init and status requests require an API key. Only the /scan redirect is public.
Header
Authorization: Bearer oa_live_xxx
Base URL
https://api.crm.emacronai.com/api/v1
Get keys
Settings → API Keys
🚫 CAUTION — Never call /magic-link/init from the browser
Your oa_live_xxx API key would be visible in the browser Network tab and could be stolen.
Browser ← { wa_link, scan_url, expires_at } ←──
Correct pattern: Frontend calls your own backend (e.g. POST /api/auth/whatsapp/init) → your backend calls EmacronAI CRM with the API key, stores the session ID against the current login attempt, and returns wa_link, scan_url, expires_at to the frontend.
If the API returns 401, check the server’s API key. A 403 indicates an access or scope issue.
POST/api/v1/whatsapp/magic-link/init
Creates a new OTPless session. Returns wa_link for mobile and scan_url for desktop QR.
Request body
Response — 200 OK
🚫 Call /init from your backend — not from React/Vue/mobile
Exposing your API key in frontend code lets anyone read it from the browser Network tab. See the Authentication section above for the correct architecture.
GET/api/v1/whatsapp/magic-link/:session_id/status
Poll every 2–3 seconds. Returns verified: true with phone and redirect_url once the user sends the WhatsApp message.
📞 Phone number format — important
The phone field is always returned in strict E.164 format with no spaces, dashes, or parentheses — e.g. +917840985216. If your database stores numbers with spaces or formatting, a direct string comparison will silently return 0 rows. Always normalize both sides before comparing:
redirect_url — return users to your app
Supply redirect_url in the init request to give users a return destination. Project keys require an approved HTTPS origin. The WhatsApp reply includes this link when the project’s return-link option is enabled. The verified status response also returns it.
Your backend completes login after checking the status of its own pending session. Keep credentials and login tokens out of URLs.
Desktop QR code + Mobile button
On desktop, users cannot tap a wa.me link. Show a QR code using scan_url (a short ~70-char URL — produces a clean, easy-to-scan code). On mobile, show a <a href={wa_link}> button that opens WhatsApp directly. Detect device with navigator.userAgent.
📱 Mobile
Show wa_link as an anchor tag. Tapping opens WhatsApp with the pre-filled message.
🖥️ Desktop
Show QR code with scan_url as value. User scans with phone, WhatsApp opens, they send the message.
⚠️ React gotcha — countdown initialization causes instant false expiry
When state transitions to "pending", there is a render cycle where your countdown hasn't initialized yet and still reads 0. If you use secondsLeft === 0 as the expiry trigger, the handler fires instantly on the first render — showing “session expired” before the user even sees the QR code.
// ❌ Dangerous — triggers instantly on first render
const [secondsLeft, setSecondsLeft] = useState(0); useEffect(() => { if (state === "pending" && secondsLeft === 0) expire(); // fires immediately! }, [secondsLeft]);// ✅ Safe — initialize to expires_in (e.g. 300)
const [secondsLeft, setSecondsLeft] = useState(300); // not 0 // Let polling handle real expiry — server returns 400 when expired. // Use the countdown only as a UX display indicator, not for control flow.OTPless message settings
Edit project wording and return-link settings in Settings → API Keys. For legacy integrations, manage the workspace defaults in Settings → WhatsApp OTP → OTPless.