{"record":{"id":"9ab5c158af25d6ea","repo":"gitroomhq/postiz-app","slug":"user-not-found-9ab5c1","errorCode":null,"errorMessage":"User not found","messagePattern":"User not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"libraries/nestjs-libraries/src/database/prisma/users/users.repository.ts","lineNumber":29,"sourceCode":"import { makeId } from '@gitroom/nestjs-libraries/services/make.is';\n\n@Injectable()\nexport class UsersRepository {\n  constructor(\n    private _user: PrismaRepository<'user'>,\n    private _transaction: PrismaTransaction\n  ) {}\n\n  async switchUserCredentials(currentUserId: string, targetUserId: string) {\n    const current = await this._user.model.user.findUnique({\n      where: { id: currentUserId },\n    });\n    const target = await this._user.model.user.findUnique({\n      where: { id: targetUserId },\n    });\n\n    if (!current || !target) {\n      throw new Error('User not found');\n    }\n\n    const currentCredentials = {\n      email: current.email,\n      password: current.password,\n      providerName: current.providerName,\n      providerId: current.providerId,\n      account: current.account,\n      connectedAccount: current.connectedAccount,\n      activated: current.activated,\n    };\n    const targetCredentials = {\n      email: target.email,\n      password: target.password,\n      providerName: target.providerName,\n      providerId: target.providerId,\n      account: target.account,\n      connectedAccount: target.connectedAccount,","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/gitroomhq/postiz-app/blob/0f1647f7491a217d43eb5ae7a480484bdf0aff3e/libraries/nestjs-libraries/src/database/prisma/users/users.repository.ts#L11-L47","documentation":"UsersRepository.switchUserCredentials swaps credential fields (email, password, providerName, etc.) between two user rows — used for account switching/impersonation flows. If either the current or target user id does not resolve to a row, it throws a plain Error('User not found').","triggerScenarios":"Invoking the switch-user flow where currentUserId or targetUserId is deleted, malformed, or not present in the users table at the moment of the swap.","commonSituations":"Target account deleted while a switch session was active; hard-deleted users referenced by lingering sessions; data inconsistencies after partial user deletion; passing an org id or wrong identifier instead of a user id.","solutions":["Verify both user ids exist (query users) before initiating the switch","Re-authenticate to establish a session with valid, current user ids","Clean up dangling references to deleted users in sessions/tokens","If it persists, inspect the users table for the two ids and fix data inconsistencies"],"exampleFix":"// before\nawait usersService.switchUserCredentials(currentUserId, targetUserId);\n// after\nconst [current, target] = await Promise.all([getUser(currentUserId), getUser(targetUserId)]);\nif (current && target) await usersService.switchUserCredentials(currentUserId, targetUserId);","handlingStrategy":"validation","validationCode":"const [current, target] = await Promise.all([getUser(currentUserId), getUser(targetUserId)]);\nif (current && target) await switchUser(currentUserId, targetUserId);","typeGuard":null,"tryCatchPattern":"try {\n  await switchUser(currentUserId, targetUserId);\n} catch (e) {\n  if (/User not found/.test(String(e?.message ?? e))) await forceRelogin();\n  else throw e;\n}","preventionTips":["Re-authenticate if a switch session is older than the target account's lifetime","Purge stored target user ids when accounts are deleted"],"tags":["users","not-found","account-switching","credentials"],"backgroundTag":"user-account-not-found","analyzedSha":"0f1647f7491a217d43eb5ae7a480484bdf0aff3e","analyzedAt":"2026-08-27T12:09:55.020Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}