mirror of
https://github.com/khairul169/vaulterm.git
synced 2026-09-15 17:03:30 +07:00
feat: team access control
This commit is contained in:
@@ -6,5 +6,32 @@ export const useUser = () => {
|
||||
queryKey: ["auth", "user"],
|
||||
queryFn: authRepo.getUser,
|
||||
});
|
||||
return user;
|
||||
|
||||
if (!user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function getTeamRole(teamId?: string | null) {
|
||||
if (!user.teams?.length) {
|
||||
return false;
|
||||
}
|
||||
const team = user.teams.find((i: any) => i.id === teamId);
|
||||
return team?.role;
|
||||
}
|
||||
|
||||
function isInTeam(teamId?: string | null) {
|
||||
return getTeamRole(teamId) != null;
|
||||
}
|
||||
|
||||
function teamCanWrite(teamId?: string | null) {
|
||||
const role = getTeamRole(teamId);
|
||||
return ["admin", "owner"].includes(role);
|
||||
}
|
||||
|
||||
return {
|
||||
...user,
|
||||
getTeamRole,
|
||||
isInTeam,
|
||||
teamCanWrite,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user