Budibase/budibase · error · HTTPError
Unable to resolve current user
Error message
Unable to resolve current user
What it means
getCurrentGlobalUserId derives the caller's global user id from the authenticated context, trying ctx.user.globalId, then converting the metadata _id via getGlobalIDFromUserMetadataID, then falling back to _id. If none yields an id, the request context is not carrying a usable authenticated user, so a 400 is thrown.
Source
Thrown at packages/server/src/api/controllers/ai/chatIdentityLinks.ts:135
const assertSessionMatchesInstance = ({
workspaceId,
instance,
}: {
workspaceId?: string
instance: string
}) => {
if (!workspaceId || workspaceId !== instance) {
throw new HTTPError("Link token is not valid for this workspace", 400)
}
}
const getCurrentGlobalUserId = (ctx: UserCtx) => {
const currentUserId =
ctx.user?.globalId ||
getGlobalIDFromUserMetadataID(ctx.user?._id || "") ||
ctx.user?._id
if (!currentUserId) {
throw new HTTPError("Unable to resolve current user", 400)
}
return currentUserId
}
const providerDisplayName = (provider: ChatIdentityLinkProvider) => {
if (provider === AgentChannelProvider.MSTEAMS) {
return "Teams"
}
if (provider === AgentChannelProvider.SLACK) {
return "Slack"
}
throw provider satisfies never
}
const renderLinkConfirmationPage = (
session: ChatIdentityLinkSession,
action: stringView on GitHub (pinned to a81a902e9a)
Solutions
- Ensure the route is authenticated and the auth middleware populates ctx.user before the handler runs
- Log in again or supply valid credentials (session cookie / API token) so ctx.user contains an id
- Check the user document for missing _id/globalId and repair via user sync
- If calling internally, pass a properly shaped ContextUser with at least _id
Example fix
// before
await confirmLink(ctx) // ctx.user undefined -> 400
// after
// ensure auth middleware ran
router.post("/confirm", authMiddleware, confirmLink) // ctx.user populated Defensive patterns
Strategy: validation
Validate before calling
const userId = ctx.user?.globalId || ctx.user?._id
if (!userId) throw new Error("no authenticated user in context") Type guard
function hasResolvedUser(user?: ContextUser): user is ContextUser & { _id: string } {
return !!user && typeof user._id === "string" && user._id.length > 0
} Try / catch
try {
await api.confirmLink(instance, token)
} catch (e) {
if (e instanceof HTTPError && e.status === 400 && e.message === "Unable to resolve current user") {
// redirect to login / re-run auth middleware
}
throw e
} Prevention
- Ensure auth middleware runs before routes that need the current user
- Never call these controller helpers without a hydrated ContextUser
- Monitor user sync so _id/globalId are always present
- Add route-level guards rejecting unauthenticated requests early
When it happens
Trigger: Calling an endpoint that invokes currentGlobalUserId (e.g. identity link handoff/confirm) with a ctx.user that is empty or lacks both globalId and _id — typically an unauthenticated or improperly populated auth context reaching an authenticated route.
Common situations: Auth middleware bypassed or misordered so ctx.user is never hydrated; internal/service calls invoking controller helpers without a real user context; user metadata documents missing ids after a sync/import issue; testing endpoints without a valid session/cookie or API key.
Related errors
- userId is required
- CouchDB password not set
- Access denied to object store bucket.${err}
- Invalid bookmark query
- Invalid limit query
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/c1c19b60b18986c2.
Report an issue: GitHub.