: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(auth): return to the original page after credential review (#112587)
Tom Owers1207cd594a4c
diff --git a/frontend/src/scenes/authentication/account/credential-review/credentialReviewLogic.test.ts b/frontend/src/scenes/authentication/account/credential-review/credentialReviewLogic.test.tsnew file mode 100644index 000000000000..8b0574c05916--- /dev/null+++ b/frontend/src/scenes/authentication/account/credential-review/credentialReviewLogic.test.ts@@ -0,0 +1,52 @@+import { MOCK_DEFAULT_USER } from 'lib/api.mock'++import { router } from 'kea-router'+import { expectLogic } from 'kea-test-utils'++import api from 'lib/api'+import { removeProjectIdIfPresent } from 'lib/utils/kea-router'+import { urls } from 'scenes/urls'+import { userLogic } from 'scenes/userLogic'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { credentialReviewLogic } from './credentialReviewLogic'++describe('credentialReviewLogic', () => {+ beforeEach(() => {+ useMocks({+ get: {+ '/api/users/@me/': () => [200, MOCK_DEFAULT_USER],+ '/api/personal_api_keys/': () => [200, []],+ '/api/webauthn/credentials/': () => [200, []],+ },+ })+ initKeaTests()+ userLogic.mount()+ jest.spyOn(api, 'create').mockResolvedValue({})+ })++ afterEach(() => {+ jest.restoreAllMocks()+ })++ test.each([+ [+ 'returns to the page the user was on',+ '/data-warehouse/new-source?kind=Hubspot#configure',+ '/data-warehouse/new-source?kind=Hubspot#configure',+ ],+ ['ignores an off-site next', 'https://example.com/phish', urls.projectHomepage()],+ ])('Continue %s', async (_, next, expectedPath) => {+ router.actions.push(urls.credentialReview(next))+ const logic = credentialReviewLogic()+ logic.mount()++ logic.actions.markComplete()+ await expectLogic(logic).toFinishAllListeners()++ const actualPath = router.values.location.pathname + router.values.location.search + router.values.location.hash+ expect(removeProjectIdIfPresent(actualPath)).toEqual(removeProjectIdIfPresent(expectedPath))+ })+})diff --git a/frontend/src/scenes/authentication/account/credential-review/credentialReviewLogic.ts b/frontend/src/scenes/authentication/account/credential-review/credentialReviewLogic.tsindex d1b8722d0199..2d39d8571d1b 100644--- a/frontend/src/scenes/authentication/account/credential-review/credentialReviewLogic.ts+++ b/frontend/src/scenes/authentication/account/credential-review/credentialReviewLogic.ts@@ -3,6 +3,7 @@ import { router } from 'kea-router'import api from 'lib/api'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { getRelativeNextPath } from 'lib/utils/url'import { passkeySettingsLogic } from 'scenes/settings/user/passkeySettingsLogic'import { personalAPIKeysLogic } from 'scenes/settings/user/personalAPIKeysLogic'import { urls } from 'scenes/urls'@@ -47,7 +48,8 @@ export const credentialReviewLogic = kea<credentialReviewLogicType>([// the post-login redirect from userLogic.loadUserSuccess.userLogic.actions.credentialReviewDismissed()userLogic.actions.loadUser()- router.actions.push(urls.projectHomepage())+ const nextPath = getRelativeNextPath(router.values.searchParams['next'], location)+ router.actions.push(nextPath ?? urls.projectHomepage())},}),afterMount(({ actions }) => {diff --git a/frontend/src/scenes/urls.ts b/frontend/src/scenes/urls.tsindex 3271de14c0ff..9d46879f4b33 100644--- a/frontend/src/scenes/urls.ts+++ b/frontend/src/scenes/urls.ts@@ -203,7 +203,8 @@ export const urls = {accountConnected: (kind: string = ':kind'): string =>kind === ':kind' ? '/account-connected/:kind' : `/account-connected/${kind}`,/** One-shot credential review interstitial shown to users with existing API keys they haven't acknowledged. */- credentialReview: (): string => '/account/credential-review',+ credentialReview: (next?: string): string =>+ `/account/credential-review${next ? `?next=${encodeURIComponent(next)}` : ''}`,cliAuthorize: (): string => '/cli/authorize',cliLive: (): string => '/cli/live',passwordReset: (): string => '/reset',diff --git a/frontend/src/scenes/userLogic.ts b/frontend/src/scenes/userLogic.tsindex e51036d5afdf..d46b6d0923ea 100644--- a/frontend/src/scenes/userLogic.ts+++ b/frontend/src/scenes/userLogic.ts@@ -764,7 +764,8 @@ export const userLogic = kea<userLogicType>([!values.credentialReviewDismissedInSession &&!router.values.location.pathname.startsWith('/account/credential-review')) {- router.actions.push(urls.credentialReview())+ const { pathname, search, hash } = router.values.location+ router.actions.push(urls.credentialReview(`${pathname}${search}${hash}`))}}},