{"record":{"id":"fcde9bbb79e20a36","repo":"hcengineering/platform","slug":"sign-in-is-not-initialized","errorCode":null,"errorMessage":"Sign in is not initialized","messagePattern":"Sign in is not initialized","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"services/telegram/pod-telegram/src/telegram.ts","lineNumber":363,"sourceCode":"    }\n\n    try {\n      await conn.signIn()\n    } catch (err) {\n      this.forgetConnection(phone)\n      await conn.close()\n\n      throw err\n    }\n\n    return 'code'\n  }\n\n  async authCode (phone: string, code: string): Promise<boolean> {\n    const conn = this.conns.get(phone)\n\n    if (conn?.signInFlow === undefined) {\n      throw Error('Sign in is not initialized')\n    }\n\n    return await conn.signInFlow.code(code)\n  }\n\n  async authPass (phone: string, pass: string): Promise<void> {\n    const conn = this.conns.get(phone)\n\n    if (conn?.signInFlow === undefined) {\n      throw Error('Sign in is not initialized')\n    }\n\n    await conn.signInFlow.pass(pass)\n  }\n\n  async getOrCreate (phone: string): Promise<TelegramConnection> {\n    const existingConn = this.conns.get(phone)\n","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/telegram/pod-telegram/src/telegram.ts#L345-L381","documentation":"authCode() looks up the connection for the phone and requires an active signInFlow; if the flow was never started (init not called) or already finished/cleared, there is nothing to submit the code to, so it throws.","triggerScenarios":"authCode(phone, code) called without a prior auth flow initialization for that phone, after sign-in completed, or when conns.get(phone) returns no connection at all.","commonSituations":"Session expired or reconnect replaced the connection while the user was typing the code; calling authCode from a stale UI screen; restarting the service mid-sign-in loses flow state.","solutions":["Call the sign-in init (send code) step before authCode for the same phone","Restart the sign-in flow (send a new code) when this error is caught","Persist or re-check flow state so reconnects don't silently drop the pending flow","Disable the code submission form until the flow is confirmed active"],"exampleFix":"// before\nconst ok = await service.authCode(phone, code) // throws if flow gone\n// after\ntry {\n  await service.authCode(phone, code)\n} catch (err) {\n  if (err.message === 'Sign in is not initialized') {\n    await service.requestCode(phone) // restart flow\n  }\n}","handlingStrategy":"try-catch","validationCode":"const conn = service.getConnection(phone)\nif (conn?.signInFlow === undefined) await service.requestCode(phone) // initialize first","typeGuard":"const canSubmit = (conn: { signInFlow?: SignInFlow } | undefined): conn is { signInFlow: SignInFlow } =>\n  conn?.signInFlow !== undefined","tryCatchPattern":"try {\n  await service.authCode(phone, code)\n} catch (err) {\n  if (err.message === 'Sign in is not initialized') {\n    await service.requestCode(phone)\n  }\n}","preventionTips":["Always complete the send-code step before collecting the code","Re-initialize the flow after reconnects or service restarts","Expire the code entry UI when the flow is dropped"],"tags":["telegram","auth","state"],"backgroundTag":"auth-flow-not-initialized","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}