Introduction: In today's fast-paced digital world, user authentication is a critical aspect of web applications. With traditional login methods requiring users to remember passwords or go through the hassle of mobile OTPs, a more efficient and secure solution is needed. OTPLESS offers a groundbreaking one-tap sign-in experience using WhatsApp, revolutionizing user authentication. In this blog, we'll guide you through the process of integrating OTPLESS with your Angular application, enhancing both security and user experience.
Step 1: Install the OTPLESS SDK
To get started, simply add the OTPLESS SDK script to your login page as follows:
html<script type="text/javascript" src="<https://otpless.com/auth.js>"></script>
Ensure that your application is served over HTTPS for the widget to load correctly. Note that the widget may not function as expected on localhost or in incognito mode.
Step 2: Retrieving User's Information
Once the user successfully authenticates, the user object is returned to you. Implement the following script in your Angular application to retrieve and log the user's information:
typescriptconstructor() { window.otpless = (otplessUser) => { alert(JSON.stringify(otplessUser)); }; }
The user's information will be logged in the console as follows:
plain text{ "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "timestamp": "YYYY-MM-DD HH:MM:SS", "timezone": "+XX:XX", "mobile": { "name": "User Name", "number": "User Mobile Number" }, "email": { "name": "User Name", "email": "User Email" } }
🚩Note:
The user object is returned only after all the authentication methods configured in the SDK have been completed. If multiple methods (e.g., mobile and email) are selected, all must be verified before the user object is returned.
Optional Step: Validate User Details
To enhance the security of your application, consider validating user details from our backend. This involves exchanging the token for the user's details in a server-to-server API call.
Step 3: User Registration and Authentication
Leverage the user details obtained from the previous step to authenticate users based on your application's specific business logic. This could include creating new user accounts (sign up) or verifying existing users (sign in).
Conclusion:
Integrating OTPLESS with your Angular application brings a new level of security and convenience to user authentication. By eliminating the need for passwords and cumbersome OTPs, OTPLESS enhances user experience while ensuring data security. Implementing OTPLESS in your app can significantly increase conversion rates and foster customer trust.
Take the leap and transform your user authentication process with OTPLESS. Get started today and offer your users a seamless and secure one-tap sign-in experience that will keep them coming back for more. Happy coding!