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.