DEV Community

Jahongir Sobirov
Jahongir Sobirov

Posted on

5 lines of code = OTP login system in Telegram 🀯

Hey devs πŸ‘‹

Let's make OTP login system in just 5 lines of codes (and it's possible broπŸ˜±πŸ‘‡). There's legendary codes:

const AuthVerify = require('auth-verify');
const auth = new AuthVerify({storeTokens: 'memory', otpExpiry: '5m'}); // we save our otp in memory and otp expires after 5 minutes
auth.otp.setSender({via: 'telegram', token: 'BOT_TOKEN_HERE'}); // preparing otp sender bot
auth.otp.generate(5).set('USER_PHONE'); // we save our otp code with the key 'USER_PHONE' in memory and length of otp code is 5
auth.otp.message({to: 'USER_PHONE'}); // sending otp to user. And that's done
Enter fullscreen mode Exit fullscreen mode

And let's check the result:

Result

The logic is when user commands /start to bot .Bot requests from user his/her phone number and checks whether OTP saved for him/her in memory

Top comments (0)