{"record":{"id":"77b9397585f936a1","repo":"Mintplex-Labs/anything-llm","slug":"user-id-not-found-in-registration-token","errorCode":null,"errorMessage":"User id not found in registration token","messagePattern":"User id not found in registration token","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/endpoints/mobile/middleware/index.js","lineNumber":74,"sourceCode":"    if (!tempToken)\n      return response\n        .status(400)\n        .json({ error: \"Registration token is required\" });\n\n    const tempTokenData = MobileDevice.tempToken(tempToken);\n    if (!tempTokenData)\n      return response\n        .status(400)\n        .json({ error: \"Invalid or expired registration token\" });\n\n    // If in multi-user mode, we need to validate the user id\n    // associated exists, is not banned and then associate with locals so we can reuse it later.\n    // If not in multi-user mode then simply having a valid token is enough.\n    const multiUserMode = await SystemSettings.isMultiUserMode();\n    if (multiUserMode) {\n      if (!tempTokenData.userId)\n        return response\n          .status(400)\n          .json({ error: \"User id not found in registration token\" });\n      const user = await User.get({ id: Number(tempTokenData.userId) });\n      if (!user) return response.status(400).json({ error: \"User not found\" });\n      if (user.suspended)\n        return response\n          .status(400)\n          .json({ error: \"User is suspended - cannot register device\" });\n      response.locals.user = user;\n    }\n\n    next();\n  } catch (error) {\n    console.error(\"validRegistrationToken:error\", error);\n    response.status(500).json({\n      error: \"Invalid middleware response from validRegistrationToken\",\n    });\n  }\n}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/mobile/middleware/index.js#L56-L92","documentation":"In multi-user mode (SystemSettings.isMultiUserMode()), validRegistrationToken requires the temp token to carry a userId. registerTempToken embeds the id of the user who generated connect-info (or null in single-user mode); if userId is absent the middleware responds 400 { error: 'User id not found in registration token' }.","triggerScenarios":"connect-info was generated while the instance ran in single-user mode (tokenData.userId = null) and multi-user mode was enabled before /mobile/register ran; or an anonymous connect-info URL is used against a multi-user instance.","commonSituations":"Mode flipped between generating the QR and scanning it; the app caches an old pairing URL produced before multi-user was enabled.","solutions":["Generate a fresh connect-info while logged in as the intended user on the now-multi-user instance and rescan","Make sure connect-info is requested after the multi-user mode switch completes","Use only the ?t= token from the newest connect-info response"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await register(tempToken);\n} catch (e) {\n  if (e.status === 400 && e.body?.error === 'User id not found in registration token') {\n    const fresh = await fetchConnectInfoAs(currentUser); // token from multi-user session\n    return register(fresh);\n  }\n  throw e;\n}","preventionTips":["Regenerate connect-info after toggling multi-user mode — old URLs are mode-stamped","Discard cached pairing URLs across configuration changes","Generate connect-info from an authenticated session in multi-user deployments"],"tags":["mobile","registration","multi-user","token-claims","mode-switch"],"backgroundTag":"token-missing-claim","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-23T21:17:23.414Z"}