hcengineering/platform · error · Error
Invalid sign in method
Error message
Invalid sign in method
What it means
SignInFlow.init() enforces a strict state machine: it may only be called when _state === 'init'. Calling init after the flow has already progressed (state 'code', 'pass', or 'done') makes sending another code invalid, so it throws.
Source
Thrown at services/telegram/pod-telegram/src/telegram.ts:29
import config from './config'
import { ApiError, Code } from './error'
Logger.setLevel('none')
type SignInState = 'init' | 'code' | 'pass' | 'end'
class SignInFlow {
private _state: SignInState = 'init'
private codeHash: string | undefined
constructor (
private readonly client: TelegramClient,
private readonly phone: string,
private readonly onEnd: () => void
) {}
async init (): Promise<void> {
if (this._state !== 'init') {
throw Error('Invalid sign in method')
}
const res = await this.client.sendCode(this.creds, this.phone)
this.codeHash = res.phoneCodeHash
this._state = 'code'
}
get state (): SignInState {
return this._state
}
async code (code: string): Promise<boolean> {
if (this._state !== 'code') {
throw Error('Invalid sign in method')
}
try {
const res = await this.client.invoke(View on GitHub (pinned to 63e28dc964)
Solutions
- Create a fresh sign-in flow (re-initialize the connection) instead of reusing the old one
- Check signInFlow.state before calling init and only call it when state is 'init'
- Debounce/disable the send-code button so init is invoked once per flow
- Catch the error and surface 'sign-in already started' to the user
Example fix
// before
if (existing.flow !== undefined) await existing.flow.init() // throws if already past init
// after
if (existing.flow === undefined || existing.flow.state === 'init') {
await startSignInFlow(phone)
} Defensive patterns
Strategy: type-guard
Validate before calling
if (flow.state === 'init') await flow.init()
Type guard
const canInit = (flow: { state: SignInState }): flow is { state: 'init' } => flow.state === 'init' Try / catch
try {
await flow.init()
} catch (err) {
if (err.message === 'Invalid sign in method') {
flow = createNewSignInFlow(phone) // restart flow
}
} Prevention
- Check signInFlow.state before each step
- Disable the send-code button after first click
- Create a new flow object for each sign-in attempt instead of reusing
When it happens
Trigger: Calling signInFlow.init() twice, or calling init() after code()/pass() already advanced the flow for the same connection.
Common situations: Retrying sign-in by calling init() again instead of creating a new SignInFlow; UI double-submitting the 'send code' button.
Related errors
- User is not signed in
- Account does not exist
- Sign in is not initialized
- Token revoked
- platform.status.Unauthorized
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/5e043cc21c2da8dd.
Report an issue: GitHub.