Budibase/budibase · error · Error
No user ID provided for getting
Error message
No user ID provided for getting
What it means
getUser throws this when neither an explicit userId argument nor ctx.params.userId is present, so there is no user identifier to pass to readGlobalUser.
Source
Thrown at packages/server/src/api/controllers/public/users.ts:74
ctx.body = await getUser(ctx, response._id)
if (removed) {
ctx.extra = { message: NO_ROLES_MSG }
}
return ctx
}
function isLoggedInUser(ctx: UserCtx, user: User) {
const loggedInId = ctx.user?._id
const globalUserId = dbCore.getGlobalIDFromUserMetadataID(loggedInId!)
// check both just incase
return globalUserId === user._id || loggedInId === user._id
}
function getUser(ctx: UserCtx, userId?: string) {
if (userId) {
ctx.params = { userId }
} else if (!ctx.params?.userId) {
throw new Error("No user ID provided for getting")
}
return readGlobalUser(ctx)
}
export async function search(ctx: UserCtx, next: Next) {
const { name } = ctx.request.body
const users = await allGlobalUsers(ctx)
ctx.body = stringSearch(users, name, "email")
await next()
}
export async function create(ctx: UserCtx, next: Next) {
await createUpdateResponse(ctx)
await next()
}
export async function read(ctx: UserCtx, next: Next) {
ctx.body = await readGlobalUser(ctx)View on GitHub (pinned to a81a902e9a)
Solutions
- Ensure the route defines /:userId and Koa populates ctx.params.userId
- Pass the userId explicitly when calling getUser programmatically
- Check middleware isn't resetting ctx.params
Example fix
// before
await getUser(ctx) // ctx.params is empty
// after
await getUser(ctx, userId) // or ensure ctx.params = { userId } Defensive patterns
Strategy: validation
Validate before calling
if (!userId && !ctx.params?.userId) throw new Error('A userId must be provided via params or argument') Type guard
function hasUserId(ctx: { params?: { userId?: string } }, userId?: string): ctx is { params: { userId: string } } {
return typeof userId === 'string' || typeof ctx.params?.userId === 'string'
} Try / catch
try {
await getUser(ctx, userId)
} catch (err) {
if (err.message === 'No user ID provided for getting') {
// recover by reading userId from the authenticated session or request body
}
} Prevention
- Verify routes declare /:userId in the path
- Pass userId explicitly when invoking controller helpers outside HTTP routing
- Never have middleware delete or overwrite ctx.params
When it happens
Trigger: Calling the public users controller helpers (createUpdateResponse or user route wrappers) without a userId in params and without passing one to getUser.
Common situations: Route misconfiguration where :userId is missing from the path; calling the controller function programmatically without params; middleware stripping params.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- Unable to delete self.
- Email is required
- Replacing members is not allowed
- Max limit for upload is 1000 users. Please reduce file size
- User must be provided for password recovery.
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/182be68284dcd8c0.
Report an issue: GitHub.