I'm trying to log into the telegram with this library: https://github.com/Bannerets/tdl, I need to send the phone number and code through the frontend, the only way I saw to do this was using socket.io, when I use a promise with a socket it works normally, but when I do it twice nothing just happens.
Backend:
io.on('connection', async (socket) => {
console.log('a user connected');
await client.login(() => ({
getPhoneNumber: () => {
return new Promise((resolve, reject) => {
socket.on('phone:submitted', async (msg) => {
resolve(msg);
});
});
},
getAuthCode: () => {
return new Promise((resolve, reject) => {
socket.on('code:submitted', async (msg) => {
resolve(msg);
});
});
},
}));
});
Frontend:
var socket = io('http://localhost:3000');
socket.emit('phone:submitted', '+1234567890');
if I just put this: it works:
io.on('connection', async (socket) => {
console.log('a user connected');
await client.login(() => ({
getPhoneNumber: () => {
return new Promise((resolve, reject) => {
socket.on('phone:submitted', async (msg) => {
resolve(msg);
});
});
}
}));
});