Fixes disable branding for teams and users (#5913)

* Adding new nextauth object

* Use correct brand hidden values

* Move check to getprops instead of a function

* Update apps/web/components/booking/pages/AvailabilityPage.tsx

* Update apps/web/components/booking/pages/AvailabilityPage.tsx

* Update apps/web/pages/[user]/[type].tsx

Co-authored-by: Leo Giovanetti <hello@leog.me>

* Update apps/web/pages/api/auth/[...nextauth].tsx

Co-authored-by: Leo Giovanetti <hello@leog.me>

* Update apps/web/pages/api/auth/[...nextauth].tsx

Co-authored-by: Leo Giovanetti <hello@leog.me>

Co-authored-by: Leo Giovanetti <hello@leog.me>
This commit is contained in:
sean-brydonandLeo Giovanetti authored and GitHub committed 2022-12-07 15:04:04 +00:00
1 parent c3122c82e4
commit f4ed345a87
9 files changed
+57 -10

No files matched your search

@@ -11,7 +11,8 @@ const teamIdschema = z.object({
const auditAndReturnNextUser = async (
impersonatedUser: Pick<User, "id" | "username" | "email" | "name" | "role">,
impersonatedByUID: number
impersonatedByUID: number,
hasTeam?: boolean
) => {
// Log impersonations for audit purposes
await prisma.impersonations.create({
@@ -36,6 +37,7 @@ const auditAndReturnNextUser = async (
name: impersonatedUser.name,
role: impersonatedUser.role,
impersonatedByUID,
belongsToActiveTeam: hasTeam,
};
return obj;
@@ -103,7 +105,11 @@ const ImpersonationProvider = CredentialsProvider({
if (impersonatedUser.disableImpersonation) {
throw new Error("This user has disabled Impersonation.");
}
return auditAndReturnNextUser(impersonatedUser, session?.user.id as number);
return auditAndReturnNextUser(
impersonatedUser,
session?.user.id as number,
impersonatedUser.teams.length > 0 // If the user has any teams, they belong to an active team and we can set the hasActiveTeam ctx to true
);
}
if (!teamId) throw new Error("You do not have permission to do this.");
@@ -137,7 +143,11 @@ const ImpersonationProvider = CredentialsProvider({
throw new Error("You do not have permission to do this.");
}
return auditAndReturnNextUser(impersonatedUser, session?.user.id as number);
return auditAndReturnNextUser(
impersonatedUser,
session?.user.id as number,
impersonatedUser.teams.length > 0 // If the user has any teams, they belong to an active team and we can set the hasActiveTeam ctx to true
);
},
});
+1
View File
@@ -14,6 +14,7 @@ declare module "next-auth" {
emailVerified?: PrismaUser["emailVerified"];
email_verified?: boolean;
impersonatedByUID?: number;
belongsToActiveTeam?: boolean;
username?: PrismaUser["username"];
role?: PrismaUser["role"];
}