Utilize our Headless SDK for ultimate flexibility. This guide provides detailed instructions on integrating custom UI elements with OTPLESS’s backend authentication functions.
This is the new Headless authentication SDK that is significantly faster and more robust than the previous version. This upgrade enhances performance, reliability, and security, ensuring a seamless authentication experience, along with a seamless integration process. We strongly recommend migrating to the new SDK for improved efficiency and better support. To migrate from the old SDK, remove the previous SDK dependency and integration and follow the below mentioned steps.
Replace YOUR_APP_ID with your actual App
ID provided in
your OTPLESS dashboard.
Add Network Security Config inside your android/app/src/main/AndroidManifest.xml file into your <application> code block (Only required if you are using the SNA feature):
Replace YOUR_APP_ID with your actual App
ID provided in
your OTPLESS dashboard.
Add Network Security Config inside your android/app/src/main/AndroidManifest.xml file into your <application> code block (Only required if you are using the SNA feature):
Replace YOUR_APP_ID with your actual App
ID provided in
your OTPLESS dashboard.
Add a method to receive callbacks from OtplessHeadlessModule.
login_page.tsx
constonHeadlessResult=(result:any)=>{ headlessModule.commitResponse(result);const responseType = result.responseType;switch(responseType){case"SDK_READY":{// Notify that SDK is readyconsole.log("SDK is ready");break;}case"FAILED":{console.log("SDK initialization failed");// Handle SDK initialization failurebreak;}case"INITIATE":{// Notify that headless authentication has been initiatedif(result.statusCode ==200){console.log("Headless authentication initiated");const authType = result.response.authType;// This is the authentication typeif(authType ==="OTP"){// Take user to OTP verification screen}elseif(authType ==="SILENT_AUTH"){// Handle Silent Authentication initiation by showing // loading status for SNA flow.}}else{// Handle initiation error. // To handle initiation error response, please refer to the error handling section.if(Platform.OS==='ios'){handleInitiateErrorIOS(result.response);}elseif(Platform.OS==='android'){handleInitiateErrorAndroid(result.response);}}break;}case"OTP_AUTO_READ":{// OTP_AUTO_READ is triggered only in Android devices for WhatsApp and SMS.if(Platform.OS==="android"){const otp = result.response.otp;console.log(`OTP Received: ${otp}`);}break;}case"VERIFY":{// notify that verification has failed.if(result.response.authType =="SILENT_AUTH"){if(result.statusCode ==9106){// Silent Authentication and all fallback authentication methods in SmartAuth have failed.// The transaction cannot proceed further. // Handle the scenario to gracefully exit the authentication flow }else{// Silent Authentication failed. // If SmartAuth is enabled, the INITIATE response // will include the next available authentication method configured in the dashboard.}}else{// To handle verification failed response, please refer to the error handling section.if(Platform.OS==='ios'){handleVerifyErrorIOS(result.response);}elseif(Platform.OS==='android'){handleVerifyErrorAndroid(result.response);}}break;}case"DELIVERY_STATUS":{// This function is called when delivery is successful for your authType.const authType = result.response.authType;// It is the authentication type (OTP, MAGICLINK, OTP_LINK) for which the delivery status is being sentconst deliveryChannel = result.response.deliveryChannel;// It is the delivery channel (SMS, WHATSAPP, etc) on which the authType has been delivered}case"ONETAP":{const token = result.response.token;if(token !=null){console.log(`OneTap Data: ${token}`);// Process token and proceed. }break;}case"FALLBACK_TRIGGERED":{// A fallback occurs when an OTP delivery attempt on one channel fails, // and the system automatically retries via the subsequent channel selected on Otpless Dashboard. // For example, if a merchant opts for SmartAuth with primary channal as WhatsApp and secondary channel as SMS,// in that case, if OTP delivery on WhatsApp fails, the system will automatically retry via SMS.// The response will contain the deliveryChannel to which the OTP has been sent.if(response.response.deliveryChannel !=null){const newDeliveryChannel = response.response.deliveryChannel // This is the deliveryChannel to which the OTP has been sent}break;}default:{console.warn(`Unknown response type: ${responseType}`);break;}}};
To verify the OTP entered by the user, use the verify method with the necessary parameters. Verifying OTP is required only in case of OTP authentication. No need to verify OTP in case of MAGICLINK.
To verify the OTP entered by the user, use the verify method with the necessary parameters. Verifying OTP is required only in case of OTP authentication. No need to verify OTP in case of MAGICLINK.
To verify the OTP entered by the user, use the verify method with the necessary parameters. Verifying OTP is required only in case of OTP authentication. No need to verify OTP in case of MAGICLINK.
OAuth Authentication 🔑
OAuth allows users to authenticate using third-party services like Google, GitHub, or WhatsApp. Instead of entering credentials manually, users can log in using their existing accounts, streamlining the authentication process.
This is the list of channels you can use for OAuth login:
WHATSAPP
APPLE
GMAIL
TWITTER
DISCORD
SLACK
FACEBOOK
LINKEDIN
MICROSOFT
LINE
LINEAR
NOTION
TWITCH
GITHUB
BITBUCKET
ATLASSIAN
GITLAB
conststartOAuth=()=>{const request ={ channelType:"WHATSAPP"};// Replace WHATSAPP with the desired channel headlessModule.start(request);};
Make sure the channel that you have selected is enabled on the dashboard.
functionhandleInitiateErrorIOS(response:any){const errorCode = response?.errorCode asstring;const errorMessage = response?.errorMessage asstring;if(!errorCode){console.log("OTPless Error: Unknown error -", errorMessage);return;}switch(errorCode){case"7101":console.log(`OTPless Error: Invalid parameters values or missing parameters - ${errorMessage ??"Unknown error"}`);break;case"7102":console.log(`OTPless Error: Invalid phone number - ${errorMessage ??"Unknown error"}`);break;case"7103":console.log(`OTPless Error: Invalid phone number delivery channel - ${errorMessage ??"Unknown error"}`);break;case"7104":console.log(`OTPless Error: Invalid email - ${errorMessage ??"Unknown error"}`);break;case"7105":console.log(`OTPless Error: Invalid email channel - ${errorMessage ??"Unknown error"}`);break;case"7106":console.log(`OTPless Error: Invalid phone number or email - ${errorMessage ??"Unknown error"}`);break;case"7113":console.log(`OTPless Error: Invalid expiry - ${errorMessage ??"Unknown error"}`);break;case"7116":console.log(`OTPless Error: OTP Length is invalid (4 or 6 only allowed) - ${errorMessage ??"Unknown error"}`);break;case"7121":console.log(`OTPless Error: Invalid app hash - ${errorMessage ??"Unknown error"}`);break;case"4000":console.log(`OTPless Error: Invalid request values - ${errorMessage ??"Unknown error"}`);break;case"4001":console.log(`OTPless Error: Unsupported 2FA request - ${errorMessage ??"Unknown error"}`);break;case"4003":console.log(`OTPless Error: Incorrect request channel - ${errorMessage ??"Unknown error"}`);break;case"401":case"7025":console.log(`OTPless Error: Unauthorized request or country not enabled - ${errorMessage ??"Unknown error"}`);break;case"7020":case"7022":case"7023":case"7024":console.log(`OTPless Error: Rate limiting error (Too many requests) - ${errorMessage ??"Unknown error"}`);break;// Feature not supported on older iOS versionscase"5900":console.log(`OTPless Error: The feature is not supported because it requires a newer iOS version - ${errorMessage ??"The requested feature is only available on newer iOS versions."}`);break;// Internet-related errorscase"9100":console.log(`OTPless Error: Request Timeout - ${errorMessage ??"The request took too long to complete and was aborted."}`);break;case"9101":console.log(`OTPless Error: Network Connection Was Lost - ${errorMessage ??"The connection was interrupted before the request could complete."}`);break;case"9102":console.log(`OTPless Error: DNS Lookup Failed - ${errorMessage ??"The domain name could not be resolved, possibly due to network issues."}`);break;case"9103":console.log(`OTPless Error: Cannot Connect to Server - ${errorMessage ??"The server is unreachable, possibly due to downtime or incorrect configurations."}`);break;case"9104":console.log(`OTPless Error: No Internet Connection - ${errorMessage ??"The device is not connected to the internet."}`);break;case"9105":console.log(`OTPless Error: Secure Connection Failed - ${errorMessage ??"A secure connection could not be established due to SSL/TLS issues."}`);break;case"9110":console.log(`OTPless Error: Otpless Authentication Request Cancelled - ${errorMessage ??"The authentication request was manually canceled by the user or the system."}`);break;default:console.log(`OTPless Error: ${errorMessage ??"Unknown error"}`);}}