Skip to content

Commit c5f5a44

Browse files
committed
fix(webapp): make RBAC role assignment on invite accept non-fatal
The setUserRole call in acceptInvite ran outside a try/catch, so a thrown error from the RBAC plugin escaped and turned the whole invite-accept into a 400 (the membership was already created in the transaction). Wrap it so both a returned {ok:false} and a thrown error are logged, including the stack, and never block joining the org.
1 parent dc118eb commit c5f5a44

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

apps/webapp/app/models/member.server.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,35 @@ export async function acceptInvite({
227227
};
228228
});
229229

230-
// If the invite carried an explicit RBAC role. Errors are logged, not fatal.
230+
// If the invite carried an explicit RBAC role, assign it. Best-effort: the
231+
// invite is already consumed and membership created above, so a failure here
232+
// — a returned {ok:false} or a thrown error from the plugin — must not block
233+
// joining the org. Swallow and log either way; without the catch a plugin
234+
// throw escapes and turns the whole invite-accept into a 400.
231235
if (result.rbacRoleId) {
232-
const roleResult = await rbac.setUserRole({
233-
userId: user.id,
234-
organizationId: result.organization.id,
235-
roleId: result.rbacRoleId,
236-
});
237-
if (!roleResult.ok) {
238-
logger.error("acceptInvite: skipped RBAC role assignment", {
236+
try {
237+
const roleResult = await rbac.setUserRole({
238+
userId: user.id,
239+
organizationId: result.organization.id,
240+
roleId: result.rbacRoleId,
241+
});
242+
if (!roleResult.ok) {
243+
logger.error("acceptInvite: skipped RBAC role assignment", {
244+
organizationId: result.organization.id,
245+
userId: user.id,
246+
rbacRoleId: result.rbacRoleId,
247+
reason: roleResult.error,
248+
});
249+
}
250+
} catch (error) {
251+
logger.error("acceptInvite: RBAC role assignment threw", {
239252
organizationId: result.organization.id,
240253
userId: user.id,
241254
rbacRoleId: result.rbacRoleId,
242-
reason: roleResult.error,
255+
error:
256+
error instanceof Error
257+
? { name: error.name, message: error.message, stack: error.stack }
258+
: String(error),
243259
});
244260
}
245261
}

0 commit comments

Comments
 (0)