gitroomhq/postiz-app · error · Error
User not found
Error message
User not found
What it means
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').
Source
Thrown at libraries/nestjs-libraries/src/database/prisma/users/users.repository.ts:29
import { makeId } from '@gitroom/nestjs-libraries/services/make.is';
@Injectable()
export class UsersRepository {
constructor(
private _user: PrismaRepository<'user'>,
private _transaction: PrismaTransaction
) {}
async switchUserCredentials(currentUserId: string, targetUserId: string) {
const current = await this._user.model.user.findUnique({
where: { id: currentUserId },
});
const target = await this._user.model.user.findUnique({
where: { id: targetUserId },
});
if (!current || !target) {
throw new Error('User not found');
}
const currentCredentials = {
email: current.email,
password: current.password,
providerName: current.providerName,
providerId: current.providerId,
account: current.account,
connectedAccount: current.connectedAccount,
activated: current.activated,
};
const targetCredentials = {
email: target.email,
password: target.password,
providerName: target.providerName,
providerId: target.providerId,
account: target.account,
connectedAccount: target.connectedAccount,View on GitHub (pinned to 0f1647f749)
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
Example fix
// before await usersService.switchUserCredentials(currentUserId, targetUserId); // after const [current, target] = await Promise.all([getUser(currentUserId), getUser(targetUserId)]); if (current && target) await usersService.switchUserCredentials(currentUserId, targetUserId);
Defensive patterns
Strategy: validation
Validate before calling
const [current, target] = await Promise.all([getUser(currentUserId), getUser(targetUserId)]); if (current && target) await switchUser(currentUserId, targetUserId);
Try / catch
try {
await switchUser(currentUserId, targetUserId);
} catch (e) {
if (/User not found/.test(String(e?.message ?? e))) await forceRelogin();
else throw e;
} Prevention
- Re-authenticate if a switch session is older than the target account's lifetime
- Purge stored target user ids when accounts are deleted
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid body
- Missing external url
- Integration not found
- Integration with id ${post.integration.id} not found
- Integration with id ${post?.integration?.id} not found
AI-assisted analysis of gitroomhq/postiz-app@0f1647f749 (2026-08-27).
Data as JSON: /api/errors/9ab5c158af25d6ea.
Report an issue: GitHub.