Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(onboarding): show access denied instead of onboarding for a refused project link (#111736)

posthog[bot]024f2b59a045
diff --git a/frontend/src/scenes/sceneLogic.test.tsx b/frontend/src/scenes/sceneLogic.test.tsx
index 50ec8f6a7213..1b18ec21675c 100644
--- a/frontend/src/scenes/sceneLogic.test.tsx
+++ b/frontend/src/scenes/sceneLogic.test.tsx
@@ -409,6 +409,37 @@ describe('sceneLogic', () => {
}
)
+ it("shows the project access denied scene, not onboarding, when the user's own project is not onboarded", async () => {
+ const priorAppContext = window.POSTHOG_APP_CONTEXT
+ try {
+ logic.unmount()
+ initKeaTests(
+ true,
+ {
+ ...MOCK_DEFAULT_TEAM,
+ ingested_event: false,
+ completed_snippet_onboarding: false,
+ has_completed_onboarding_for: {},
+ },
+ MOCK_DEFAULT_PROJECT,
+ { ...MOCK_DEFAULT_ORGANIZATION, teams: [MOCK_DEFAULT_TEAM] } as OrganizationType
+ )
+ await expectLogic(teamLogic).toDispatchActions(['loadCurrentTeamSuccess'])
+ featureFlagLogic.mount()
+ window.POSTHOG_APP_CONTEXT = { ...window.POSTHOG_APP_CONTEXT, project_access_denied: '12345' } as AppContext
+ const refusedLink = `/project/12345${removeProjectIdIfPresent(urls.eventDefinitions())}`
+ router.actions.push(refusedLink)
+ logic = sceneLogic.build({ scenes: testScenes })
+ logic.mount()
+ await expectLogic(logic).delay(1)
+
+ expect(router.values.location.pathname).toEqual(refusedLink)
+ expect(logic.values.activeSceneId).toEqual(Scene.ErrorProjectAccessDenied)
+ } finally {
+ window.POSTHOG_APP_CONTEXT = priorAppContext
+ }
+ })
+
describe('/home honors the configured homepage', () => {
const dashboardHomepage = {
id: 'homepage-dashboard-42',
diff --git a/frontend/src/scenes/sceneLogic.tsx b/frontend/src/scenes/sceneLogic.tsx
index f5e4072b6d73..d989f5918948 100644
--- a/frontend/src/scenes/sceneLogic.tsx
+++ b/frontend/src/scenes/sceneLogic.tsx
@@ -175,6 +175,12 @@ const pathPrefixesOnboardingNotRequiredFor = [
'/legal',
]
+// The server refused the project this address names and served the user's own one.
+function isRefusedProjectPath(pathname: string): boolean {
+ const refusedProject = getAppContext()?.project_access_denied
+ return !!refusedProject && getProjectIdentifierInPath(pathname) === refusedProject
+}
+
export function isOnboardingNotRequiredForPath(pathname: string): boolean {
const path = removeProjectIdIfPresent(pathname)
return pathPrefixesOnboardingNotRequiredFor.some((prefix) => path.startsWith(prefix))
@@ -562,12 +568,7 @@ export const sceneLogic = kea<sceneLogicType>([
// The server refused the project this address names and served the user's own one,
// so the page cannot load. Once the address bar names a project we do serve, the
// scene loads as usual.
- if (
- appContext?.project_access_denied &&
- sceneId &&
- sceneConfigurations[sceneId]?.projectBased &&
- getProjectIdentifierInPath(location.pathname) === appContext.project_access_denied
- ) {
+ if (sceneId && sceneConfigurations[sceneId]?.projectBased && isRefusedProjectPath(location.pathname)) {
return Scene.ErrorProjectAccessDenied
}
@@ -961,7 +962,9 @@ export const sceneLogic = kea<sceneLogicType>([
// If the delegation invite is cancelled or expires, the backend clears
// onboarding_delegated_to_invite and the redirect re-fires.
!isOnboardingRedirectSuppressed(user) &&
- !isOnboardingNotRequiredForPath(location.pathname)
+ !isOnboardingNotRequiredForPath(location.pathname) &&
+ // The access denied page must show, else the link silently opens the onboarding of the user's own project.
+ !isRefusedProjectPath(router.values.location.pathname)
) {
const nextUrl =
getRelativeNextPath(params.searchParams.next, location) ??