How to Send OTP in Ionic (Capacitor) — 2026
Ionic + Capacitor OTP tutorial using StartMessaging. Angular service, Capacitor SMS Retriever plugin, and a Node backend pattern.
StartMessaging Team
Engineering
Ionic with Capacitor remains a popular cross-platform path for Indian agencies and SMB SaaS. This tutorial wires StartMessaging on top of your existing Node backend.
Setup
ionic start otp-ionic blank --type angular --capacitor
cd otp-ionic
npm install @capacitor-community/sms-retrieverAngular Service
// src/app/otp.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({ providedIn: 'root' })
export class OtpService {
private base = 'https://your-backend.example.com';
constructor(private http: HttpClient) {}
send(phone: string) {
return this.http.post<{ requestId: string }>(`${this.base}/auth/send-otp`, { phoneNumber: phone });
}
verify(requestId: string, otpCode: string) {
return this.http.post<{ verified: boolean }>(`${this.base}/auth/verify-otp`, { requestId, otpCode });
}
}Login Page
// src/app/login/login.page.ts
export class LoginPage {
phone = ''; code = ''; requestId: string | null = null;
constructor(private otp: OtpService) {}
async send() {
const r = await firstValueFrom(this.otp.send(this.phone));
this.requestId = r.requestId;
}
async verify() {
await firstValueFrom(this.otp.verify(this.requestId!, this.code));
}
}SMS Auto-Fill via Capacitor
import { SmsRetriever } from '@capacitor-community/sms-retriever';
const result = await SmsRetriever.startWatch();
const code = result.message.match(/\d{6}/)?.[0];FAQ
Flutter equivalent at our Flutter guide.
Related Articles
React Native OTP tutorial using Expo and StartMessaging. Includes secure storage, auto-fill (Android SMS Retriever / iOS keychain), and a Node backend pattern.
Flutter OTP tutorial using StartMessaging on a Firebase Functions backend. Riverpod state, http client, secure cookie session via Firebase Auth custom token.
Keep TRAI DLT-compliant SMS OTP on the server: React Native and Flutter clients call your API only—never ship SMS gateway keys for OTP SMS API India integrations.
Ready to Send OTPs?
Integrate StartMessaging in 5 minutes. No DLT registration required.