Skip to content

Commit bcb6936

Browse files
devin-ai-integration[bot]Convex, Inc.
authored andcommitted
Fix custom claims flattening in dashboard 'Act as User' feature (#38306)
Fix custom claims flattening in dashboard "Act as User" feature to match real JWT behavior. **Problem**: When using the dashboard's "Act as User" feature, custom claims specified in the `customClaims` field were not being flattened to the root level of the user identity object returned by `ctx.auth.getUserIdentity()`. This caused a mismatch between real JWT tokens (where custom claims are flattened to root level) and dashboard impersonation (where custom claims remained nested), preventing users from testing functions that rely on custom claims like `scopes` arrays for authorization. **Solution**: Modified the `onImpersonatedUserChange` function in `FunctionTester.tsx` to extract `customClaims` from the parsed user object and flatten them to the root level using object spread syntax, ensuring dashboard impersonation behavior matches real JWT processing. **Changes**: - Modified `npm-packages/dashboard-common/src/features/functionRunner/components/FunctionTester.tsx` - Added custom claims flattening logic in `onImpersonatedUserChange` function - Maintains existing validation and error handling **Testing**: Code passes all linting checks (`just lint-js`) and formatting standards (`just format-js`). Local testing was blocked by PostgreSQL environment setup issues, relying on CI for comprehensive testing. GitOrigin-RevId: 3148656bf496df84da21579a8c8f58f130609b10
1 parent e1d07a8 commit bcb6936

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

npm-packages/dashboard-common/src/features/functionRunner/components/FunctionTester.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,14 @@ export function useFunctionTester({
475475
return;
476476
}
477477
const user = impersonatedUserSchema.parse(v);
478-
setImpersonatedUser(user);
478+
479+
const { customClaims, ...rootClaims } = user;
480+
const flattenedUser = {
481+
...rootClaims,
482+
...(customClaims || {}),
483+
};
484+
485+
setImpersonatedUser(flattenedUser);
479486
setImpersonatedUserError(undefined);
480487
} catch (e: any) {
481488
if (e instanceof ZodError) {

0 commit comments

Comments
 (0)