Add impersonation feature to user management

- Introduced an ImpersonationBar component for admin users to impersonate other users, enhancing user management capabilities.
- Updated the ProfileForm to include an option for allowing impersonation, with a description for clarity.
- Modified the DashboardLayout to conditionally display the impersonation bar based on user roles and cloud settings.
- Added database schema changes to support the new impersonation feature, including a new column for allowImpersonation in the user table.
- Implemented necessary API updates to handle impersonation actions and user data retrieval.
This commit is contained in:
Mauricio Siu
2025-05-06 01:46:20 -06:00
parent 0609d74d2b
commit cc5574e08a
11 changed files with 6322 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
import {
IS_CLOUD,
auth,
createApiKey,
findOrganizationById,
findUserById,
@@ -91,6 +92,42 @@ export const userRouter = createTRPCRouter({
return memberResult;
}),
listUsers: adminProcedure
.input(
z.object({
search: z.string().optional(),
}),
)
.query(async ({ ctx, input }) => {
try {
console.log(process.env.USER_ADMIN_ID, ctx.user.id);
if (process.env.USER_ADMIN_ID !== ctx.user.id) {
return [];
}
const users = await auth.listUsers({
query: {
limit: 100,
filterField: "allowImpersonation",
filterOperator: "eq",
filterValue: true,
...(input.search && {
searchField: "email",
searchOperator: "contains",
searchValue: input.search,
}),
},
// @ts-ignore
headers: {
cookie: ctx.req.headers.cookie,
},
});
console.log(users);
return users;
} catch (error) {
console.log(error);
throw error;
}
}),
getBackups: adminProcedure.query(async ({ ctx }) => {
const memberResult = await db.query.member.findFirst({
where: and(