Skip to content

Commit 7b3e6e7

Browse files
committed
refactor for public access case
1 parent 86189b2 commit 7b3e6e7

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

packages/web/src/app/[domain]/layout.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,11 @@ export default async function Layout({
3838
return notFound();
3939
}
4040

41+
const session = await auth();
4142
const publicAccessEnabled = hasEntitlement("public-access") && await getPublicAccessStatus(domain);
42-
if (!publicAccessEnabled) {
43-
const session = await auth();
44-
if (!session) {
45-
const ssoEntitlement = await hasEntitlement("sso");
46-
if (ssoEntitlement && env.AUTH_EE_GCP_IAP_ENABLED && env.AUTH_EE_GCP_IAP_AUDIENCE) {
47-
return <GcpIapAuth callbackUrl={`/${domain}`} />;
48-
} else {
49-
redirect('/login');
50-
}
51-
}
52-
43+
44+
// If the user is authenticated, we must check if they're a member of the org
45+
if (session) {
5346
const membership = await prisma.userToOrg.findUnique({
5447
where: {
5548
orgId_userId: {
@@ -61,7 +54,7 @@ export default async function Layout({
6154
user: true
6255
}
6356
});
64-
57+
6558
// There's two reasons why a user might not be a member of an org:
6659
// 1. The org doesn't require member approval, but the org was at max capacity when the user registered. In this case, we show them
6760
// the join organization card to allow them to join the org if seat capacity is freed up. This card handles checking if the org has available seats.
@@ -90,6 +83,16 @@ export default async function Layout({
9083
}
9184
}
9285
}
86+
} else {
87+
// If the user isn't authenticated and public access isn't enabled, we need to redirect them to the login page.
88+
if (!publicAccessEnabled) {
89+
const ssoEntitlement = await hasEntitlement("sso");
90+
if (ssoEntitlement && env.AUTH_EE_GCP_IAP_ENABLED && env.AUTH_EE_GCP_IAP_AUDIENCE) {
91+
return <GcpIapAuth callbackUrl={`/${domain}`} />;
92+
} else {
93+
redirect('/login');
94+
}
95+
}
9396
}
9497

9598
if (!org.isOnboarded) {

packages/web/src/initialize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const syncDeclarativeConfig = async (configPath: string) => {
114114

115115
if (hasPublicAccessEntitlement) {
116116
if (enablePublicAccess && env.SOURCEBOT_EE_AUDIT_LOGGING_ENABLED === 'true') {
117-
logger.error(`Audit logging is not supported when public access is enabled. Please disable audit logging or disable public access.`);
117+
logger.error(`Audit logging is not supported when public access is enabled. Please disable audit logging (SOURCEBOT_EE_AUDIT_LOGGING_ENABLED) or disable public access.`);
118118
process.exit(1);
119119
}
120120

0 commit comments

Comments
 (0)