Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I recived Error "PHONE_CODE_EXPIRED" when send code and signin. #655

Open
giangnv2 opened this issue Mar 27, 2024 · 1 comment
Open

I recived Error "PHONE_CODE_EXPIRED" when send code and signin. #655

giangnv2 opened this issue Mar 27, 2024 · 1 comment

Comments

@giangnv2
Copy link

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
}
@alvvaysxxx
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants