Skip to content

Scheduling infrastructure for absolutely everyone.

fix: Introduce a new prop in the session to extract the profile username when inside an org (#18979)

Anik Dhabal Babu3ecc9319c734
diff --git a/packages/features/auth/lib/getServerSession.ts b/packages/features/auth/lib/getServerSession.ts
index b5df23fca19..447a54dc134 100644
--- a/packages/features/auth/lib/getServerSession.ts
+++ b/packages/features/auth/lib/getServerSession.ts
@@ -99,6 +99,7 @@ export async function getServerSession(options: {
}),
belongsToActiveTeam: token.belongsToActiveTeam,
org: token.org,
+ orgAwareUsername: token.orgAwareUsername,
locale: user.locale ?? undefined,
profile: user.profile,
},
diff --git a/packages/features/auth/lib/next-auth-options.ts b/packages/features/auth/lib/next-auth-options.ts
index be14526ce8f..b15c5315703 100644
--- a/packages/features/auth/lib/next-auth-options.ts
+++ b/packages/features/auth/lib/next-auth-options.ts
@@ -546,6 +546,7 @@ export const getOptions = ({
profileId: profile.id,
upId,
belongsToActiveTeam,
+ orgAwareUsername: profileOrg ? profile.username : existingUser.username,
// All organizations in the token would be too big to store. It breaks the sessions request.
// So, we just set the currently switched organization only here.
// platform org user don't need profiles nor domains
@@ -580,6 +581,7 @@ export const getOptions = ({
id: user.id,
name: user.name,
username: user.username,
+ orgAwareUsername: user?.org ? user.profile?.username : user.username,
email: user.email,
role: user.role,
impersonatedBy: user.impersonatedBy,
@@ -684,6 +686,7 @@ export const getOptions = ({
impersonatedBy: token.impersonatedBy,
belongsToActiveTeam: token?.belongsToActiveTeam as boolean,
org: token?.org,
+ orgAwareUsername: token.orgAwareUsername,
locale: existingUser.locale,
} as JWT;
}
@@ -709,6 +712,7 @@ export const getOptions = ({
id: token.id as number,
name: token.name,
username: token.username as string,
+ orgAwareUsername: token.orgAwareUsername,
role: token.role as UserPermissionRole,
impersonatedBy: token.impersonatedBy,
belongsToActiveTeam: token?.belongsToActiveTeam as boolean,
diff --git a/packages/features/shell/SideBar.tsx b/packages/features/shell/SideBar.tsx
index 396dc106067..00d3a3ec414 100644
--- a/packages/features/shell/SideBar.tsx
+++ b/packages/features/shell/SideBar.tsx
@@ -57,7 +57,7 @@ export function SideBar({ bannersHeight, user }: SideBarProps) {
const isPlatformPages = pathname?.startsWith("/settings/platform");
const isAdmin = session.data?.user.role === UserPermissionRole.ADMIN;
- const publicPageUrl = `${getBookerBaseUrlSync(user?.org?.slug ?? null)}/${user?.username}`;
+ const publicPageUrl = `${getBookerBaseUrlSync(user?.org?.slug ?? null)}/${user?.orgAwareUsername}`;
const bottomNavItems = useBottomNavItems({
publicPageUrl,
diff --git a/packages/types/next-auth.d.ts b/packages/types/next-auth.d.ts
index fadae41d4ac..487cc5f3bb1 100644
--- a/packages/types/next-auth.d.ts
+++ b/packages/types/next-auth.d.ts
@@ -35,6 +35,7 @@ declare module "next-auth" {
role: MembershipRole;
};
username?: PrismaUser["username"];
+ orgAwareUsername?: PrismaUser["username"];
avatarUrl?: PrismaUser["avatarUrl"];
role?: PrismaUser["role"] | "INACTIVE_ADMIN";
locale?: string | null;
@@ -66,6 +67,7 @@ declare module "next-auth/jwt" {
domainSuffix: string;
role: MembershipRole;
};
+ orgAwareUsername?: PrismaUser["username"];
organizationId?: number | null;
locale?: string;
}