Skip to content

fix(telegram-bridge): QR login, real resendCode, honest delivery type, login that survives a redeploy - #1042

Open
gHashTag wants to merge 1 commit into
mainfrom
fix/telegram-qr-login
Open

gHashTag wants to merge 1 commit into
mainfrom
fix/telegram-qr-login

Conversation

@gHashTag

Copy link
Copy Markdown
Owner

Four defects on one login screen, reported by Дмитрий dsbusiness2026@gmail.com against app.t27.ai.

The report, and what was true

sentCodeTypeApp delivers the login code to other logged-in sessions of the same number. A user whose only session is the one they are trying to create has nowhere to receive it — the code is not lost in transit, it was delivered to a set of zero devices. The bridge discarded auth.sentCode's Type, Timeout and NextType and let the UI guess "приложение/SMS", so that user was told to watch for an SMS that could never arrive.

All three points he raised without asking for verification were correct.

What changed

Defect Fix
UI guessed the delivery channel SendCode returns a SentCode carrying channel, code length, Telegram's own timeout and the nominated next channel. /auth/phone reports the channel Telegram named; an unrecognised type is reported as unknown, never as app
"Request a new code" repeated sendCode New ResendCode calls auth.resendCode, honours the timeout from the response, and refuses outright when Telegram nominated no next channel rather than appearing to retry
No route independent of code delivery auth_qr.go: auth.exportLoginToken → tg://login?token=…, polled via /auth/qr/status, with SESSION_PASSWORD_NEEDED routed to the existing Check2FA so 2FA reuses the screen that already exists
Redeploy killed in-flight logins handleConnect used session.FileStorage on a container filesystem. Now Postgres, with the pending flow persisted and getClient restoring it before declaring a session invalid

PostgresSessionStorage was already written and unused, and referenced a telegram_sessions table nothing in the repository created. Both tables are now created at startup.

Not claimed

Whether our api_id fell under a silent block. The symptoms match indexit#79, but there is no confirmation from our side — and until this branch, resend was the wrong call anyway, so SEND_CODE_UNAVAILABLE would never have surfaced.

Verification

go build ./..., go vet ./internal/..., go test ./internal/telegram/ — all green. Tests cover the delivery-type mapping, that an unknown type is never reported as app, and that a resend with no next channel refuses.

Not exercised against live Telegram: the QR scan and the DC-migration path need a real account.

🤖 Generated with Claude Code

…old them to wait

Four defects on one login screen, reported by Dmitrii <dsbusiness2026@gmail.com>.

sentCodeTypeApp delivers to other logged-in sessions of the same number. A user
whose only session is the one they are creating has nowhere to receive it. The
bridge discarded auth.sentCode's Type, Timeout and NextType and let the UI guess
"app/SMS", so that user was advised to watch for an SMS that could never arrive.
SendCode now returns all four and the handler states the channel Telegram named.

"Request a new code" called sendCode again, which is free to pick the same dead
channel. It now calls auth.resendCode, honours Telegram's own timeout instead of
a locally invented one, and refuses outright when Telegram nominated no next
channel rather than pretending to try.

QR login is added as the route that does not depend on code delivery at all:
auth.exportLoginToken, polled, with SESSION_PASSWORD_NEEDED handed to the
existing Check2FA so 2FA reuses the screen that already exists.

The in-flight login lived in process memory and in a FileStorage on a container
filesystem, so any redeploy between "enter phone" and "enter code" silently
killed it. It now persists to Postgres and getClient restores it. The storage
this uses was already written and unused, aimed at a telegram_sessions table
nothing in the repository created; the table is created here too.

Tests cover the delivery-type mapping, that an unknown type is never reported
as "app", and that a resend without a next channel refuses.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants