{"record":{"id":"5e043cc21c2da8dd","repo":"hcengineering/platform","slug":"invalid-sign-in-method","errorCode":null,"errorMessage":"Invalid sign in method","messagePattern":"Invalid sign in method","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"services/telegram/pod-telegram/src/telegram.ts","lineNumber":29,"sourceCode":"import config from './config'\nimport { ApiError, Code } from './error'\n\nLogger.setLevel('none')\n\ntype SignInState = 'init' | 'code' | 'pass' | 'end'\nclass SignInFlow {\n  private _state: SignInState = 'init'\n  private codeHash: string | undefined\n\n  constructor (\n    private readonly client: TelegramClient,\n    private readonly phone: string,\n    private readonly onEnd: () => void\n  ) {}\n\n  async init (): Promise<void> {\n    if (this._state !== 'init') {\n      throw Error('Invalid sign in method')\n    }\n\n    const res = await this.client.sendCode(this.creds, this.phone)\n    this.codeHash = res.phoneCodeHash\n    this._state = 'code'\n  }\n\n  get state (): SignInState {\n    return this._state\n  }\n\n  async code (code: string): Promise<boolean> {\n    if (this._state !== 'code') {\n      throw Error('Invalid sign in method')\n    }\n\n    try {\n      const res = await this.client.invoke(","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/telegram/pod-telegram/src/telegram.ts#L11-L47","documentation":"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.","triggerScenarios":"Calling signInFlow.init() twice, or calling init() after code()/pass() already advanced the flow for the same connection.","commonSituations":"Retrying sign-in by calling init() again instead of creating a new SignInFlow; UI double-submitting the 'send code' button.","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"],"exampleFix":"// before\nif (existing.flow !== undefined) await existing.flow.init() // throws if already past init\n// after\nif (existing.flow === undefined || existing.flow.state === 'init') {\n  await startSignInFlow(phone)\n}","handlingStrategy":"type-guard","validationCode":"if (flow.state === 'init') await flow.init()","typeGuard":"const canInit = (flow: { state: SignInState }): flow is { state: 'init' } => flow.state === 'init'","tryCatchPattern":"try {\n  await flow.init()\n} catch (err) {\n  if (err.message === 'Invalid sign in method') {\n    flow = createNewSignInFlow(phone) // restart flow\n  }\n}","preventionTips":["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"],"tags":["telegram","auth","state-machine"],"backgroundTag":"invalid-auth-state-transition","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}