feat: implement user impersonation feature (#976)
* feat: wip impersonate user * feat: add ability to impersonate an user * fix: remove console.log * fix: unused import
This commit is contained in:
@ -165,4 +165,41 @@ export class AuthService {
|
||||
|
||||
return { isValid: !!workspace };
|
||||
}
|
||||
|
||||
async impersonate(
|
||||
userId: string,
|
||||
select: Prisma.UserSelect & {
|
||||
id: true;
|
||||
workspaceMember: {
|
||||
select: {
|
||||
allowImpersonation: true;
|
||||
};
|
||||
};
|
||||
},
|
||||
) {
|
||||
const user = await this.userService.findUnique({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
select,
|
||||
});
|
||||
|
||||
assert(user, "This user doesn't exist", NotFoundException);
|
||||
assert(
|
||||
user.workspaceMember?.allowImpersonation,
|
||||
'Impersonation not allowed',
|
||||
ForbiddenException,
|
||||
);
|
||||
|
||||
const accessToken = await this.tokenService.generateAccessToken(user.id);
|
||||
const refreshToken = await this.tokenService.generateRefreshToken(user.id);
|
||||
|
||||
return {
|
||||
user,
|
||||
tokens: {
|
||||
accessToken,
|
||||
refreshToken,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user