Open giangnv2 opened 5 months ago
My code:
const session = new StringSession(''); const client = new TelegramClient(session, apiId, apiHash, {}); const getPhoneHash = async () => { try { await client.connect(); } catch (error) { console.error('Error:', error); } const {phoneCodeHash, isCodeViaApp} = await client.sendCode({ apiId: apiId, apiHash: apiHash, }, phone); setPhoneHash(phoneCodeHash) console.log(phoneCodeHash, isCodeViaApp) } const confirmLogin = async () => { try { await client.connect(); } catch (error) { console.error('Error:', error); } console.log(phoneCode, phoneHash, phone) const result = await client.invoke( new Api.auth.SignIn({ phoneNumber: phone, phoneCodeHash: phoneHash, phoneCode: phoneCode, }) ); console.log(result); // prints the result }
that's because you should send code and sign in in one session, but you are using 2 client.connect() so it means that its 2 different sessions. If you need more clarification then reply me
My code: