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.

perf(auth): keep the login and passkey logics off the shell (#127342)

Paul D'Ambra236e4f7afc5a
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjs
index 1d1aed72283a..e0f46362bda1 100644
--- a/frontend/bin/check-eager-graph.mjs
+++ b/frontend/bin/check-eager-graph.mjs
@@ -144,6 +144,9 @@ const ROOTS = [
'products/subscriptions/frontend/components/Subscriptions/exportNudge/exportNudgeLogic.ts',
// The pay gate loads the payment logic on click. It pulls in the billing product logic.
'src/scenes/billing/paymentEntryLogic.ts',
+ // The login scene's logics. Shell code reads the login redirect from lib/utils/loginRedirect.
+ 'src/scenes/authentication/auth/loginLogic.ts',
+ 'src/scenes/authentication/shared/passkeyLogic.ts',
// The rich text editor stack is for the scenes that edit text. Rendered markdown needs none of it.
'node_modules/@tiptap/',
'node_modules/prosemirror-',
diff --git a/frontend/bin/layer-baseline.txt b/frontend/bin/layer-baseline.txt
index a6d6e5f1cf9b..31ca16f05d49 100644
--- a/frontend/bin/layer-baseline.txt
+++ b/frontend/bin/layer-baseline.txt
@@ -252,7 +252,6 @@ frontend/src/lib/components/Sharing/SharingModal.tsx -> frontend/src/scenes/insi
frontend/src/lib/components/SmoothingFilter/SmoothingFilter.tsx -> frontend/src/scenes/insights/insightLogic.tsx
frontend/src/lib/components/SmoothingFilter/SmoothingFilter.tsx -> frontend/src/scenes/insights/insightVizDataLogic.ts
frontend/src/lib/components/SmoothingFilter/SmoothingFilter.tsx -> products/product_analytics/frontend/insights/trends/trendsDataLogic.ts
-frontend/src/lib/components/SocialLoginButton/SocialLoginButton.tsx -> frontend/src/scenes/authentication/shared/passkeyLogic.ts
frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.tsx -> frontend/src/scenes/surveys/hooks/useSurveyResponseColumns.tsx
frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.tsx -> frontend/src/scenes/surveys/surveyLogic.tsx
frontend/src/lib/components/SurveyResponseDisplay/SurveyResponseDisplay.tsx -> frontend/src/scenes/surveys/utils.ts
@@ -470,7 +469,6 @@ frontend/src/scenes/AuthenticatedShell.tsx -> products/webmcp/frontend/logics/we
frontend/src/scenes/appScenes.ts -> frontend/src/scenes/project-homepage/importProjectHomepage.ts
frontend/src/scenes/bootApp.ts -> frontend/src/scenes/notebooks/AddToNotebook/registerNotebookLinkDrag.ts
frontend/src/scenes/sceneLogic.tsx -> frontend/src/exporter/exporterViewLogic.ts
-frontend/src/scenes/sceneLogic.tsx -> frontend/src/scenes/authentication/auth/loginLogic.ts
frontend/src/scenes/sceneLogic.tsx -> frontend/src/scenes/coupons/utils.ts
frontend/src/scenes/sceneLogic.tsx -> frontend/src/scenes/onboarding/onboardingDelegationState.ts
frontend/src/scenes/scenes.ts -> frontend/src/scenes/activity/explore/defaults.ts
diff --git a/frontend/src/lib/components/SocialLoginButton/SocialLoginButton.tsx b/frontend/src/lib/components/SocialLoginButton/SocialLoginButton.tsx
index 688fb02b2905..a64619d09a8f 100644
--- a/frontend/src/lib/components/SocialLoginButton/SocialLoginButton.tsx
+++ b/frontend/src/lib/components/SocialLoginButton/SocialLoginButton.tsx
@@ -1,13 +1,15 @@
import clsx from 'clsx'
-import { useActions, useValues } from 'kea'
+import { useValues } from 'kea'
import { router } from 'kea-router'
+import { Component, type ReactNode, Suspense } from 'react'
import { SSO_PROVIDER_NAMES } from 'lib/constants'
import { LemonButton, LemonButtonWithoutSideActionProps } from 'lib/lemon-ui/LemonButton'
import { LemonDivider } from 'lib/lemon-ui/LemonDivider'
import { LemonTag } from 'lib/lemon-ui/LemonTag'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { BeginPasskeyLoginParams, passkeyLogic } from 'scenes/authentication/shared/passkeyLogic'
+import { isChunkLoadError } from 'lib/utils/isChunkLoadError'
+import { lazyWithRetry } from 'lib/utils/retryImport'
import { LoginMethod, SSOProvider } from '~/types'
@@ -15,6 +17,11 @@ import passkeyLogo from './passkey.svg'
import { SocialLoginIcon } from './SocialLoginIcon'
import { getSocialLoginUrl } from './socialLoginUrl'
+// The passkey flow pulls in the login logic and the WebAuthn browser library.
+const PasskeyLoginButton = lazyWithRetry(() =>
+ import('scenes/authentication/shared/PasskeyLoginButton').then((m) => ({ default: m.PasskeyLoginButton }))
+)
+
interface SocialLoginLinkProps {
provider: SSOProvider
extraQueryParams?: Record<string, string>
@@ -90,40 +97,46 @@ export function SocialLoginButton({
)
}
-interface PasskeyLoginButtonProps {
- isLastUsed?: boolean
- extraQueryParams?: Record<string, string>
+/** Holds the passkey button's place while its chunk loads, or when the chunk fails to load. */
+function PasskeyButtonPlaceholder({
+ loading,
+ disabledReason,
+}: {
+ loading?: boolean
+ disabledReason?: string
+}): JSX.Element {
+ return (
+ <LemonButton
+ size="large"
+ icon={<img src={passkeyLogo} alt="Passkey" className="object-contain w-7 h-7" />}
+ tooltip={disabledReason ? undefined : 'Passkey'}
+ htmlType="button"
+ loading={loading}
+ disabledReason={disabledReason}
+ />
+ )
}
-export function PasskeyLoginButton({ isLastUsed, extraQueryParams }: PasskeyLoginButtonProps): JSX.Element {
- const { beginPasskeyLogin } = useActions(passkeyLogic)
- const { isLoading } = useValues(passkeyLogic)
+/** The re-authentication modal also shows the passkey button, and a page reload there would discard
+ * the user's work. So a failed chunk load disables the button in place instead of reloading. */
+class PasskeyChunkLoadBoundary extends Component<{ children: ReactNode }, { error: unknown }> {
+ override state: { error: unknown } = { error: null }
- return (
- <div className="relative">
- <LemonButton
- size="large"
- icon={<img src={passkeyLogo} alt="Passkey" className="object-contain w-7 h-7" />}
- active={isLastUsed}
- tooltip="Passkey"
- htmlType="button"
- onClick={() => {
- beginPasskeyLogin(undefined, extraQueryParams as BeginPasskeyLoginParams)
- }}
- loading={isLoading}
- data-attr="passkey-login"
- />
- {isLastUsed && (
- <LemonTag
- type="muted"
- size="small"
- className="absolute -top-3 left-1/2 -translate-x-1/2 pointer-events-none"
- >
- Last used
- </LemonTag>
- )}
- </div>
- )
+ static getDerivedStateFromError(error: unknown): { error: unknown } {
+ return { error }
+ }
+
+ override render(): ReactNode {
+ if (!this.state.error) {
+ return this.props.children
+ }
+ if (!isChunkLoadError(this.state.error)) {
+ throw this.state.error
+ }
+ return (
+ <PasskeyButtonPlaceholder disabledReason="Passkey sign-in couldn't load. Refresh the page to try again, or use another sign-in method." />
+ )
+ }
}
interface SocialLoginButtonsProps {
@@ -195,7 +208,13 @@ export function SocialLoginButtons({
{...props}
/>
))}
- {showPasskey && <PasskeyLoginButton isLastUsed={lastUsedProvider === 'passkey'} {...props} />}
+ {showPasskey && (
+ <PasskeyChunkLoadBoundary>
+ <Suspense fallback={<PasskeyButtonPlaceholder loading />}>
+ <PasskeyLoginButton isLastUsed={lastUsedProvider === 'passkey'} {...props} />
+ </Suspense>
+ </PasskeyChunkLoadBoundary>
+ )}
</div>
{caption && captionLocation === 'bottom' && <p className="text-secondary">{caption}</p>}
</div>
diff --git a/frontend/src/lib/utils/loginRedirect.ts b/frontend/src/lib/utils/loginRedirect.ts
new file mode 100644
index 000000000000..70415a072154
--- /dev/null
+++ b/frontend/src/lib/utils/loginRedirect.ts
@@ -0,0 +1,124 @@
+import { encodeParams, router } from 'kea-router'
+import posthog from 'posthog-js'
+
+import { getCurrentTeamIdOrNone, isUserLoggedIn } from 'lib/utils/getAppContext'
+import { getRelativeNextPath } from 'lib/utils/url'
+
+// Routes that should be handled by Django, not the React router
+const BACKEND_ONLY_ROUTES = [
+ '/login/vercel/continue',
+ '/oauth/authorize',
+ '/toolbar_oauth/authorize',
+ '/toolbar_oauth/check',
+]
+
+const PROJECT_PATH_PREFIX = '/project/'
+
+// True when the path targets a project other than the one we're currently in. A client-side
+// history replace can't switch the active project, so `AutoProjectMiddleware` never runs and any
+// team-scoped scene resolves against the wrong project and 404s. The project segment is either a
+// numeric team id or a token (a `phc_` project key, or a legacy api_token from the middleware's
+// switching allowlist), and only the server can resolve a token to a team, so anything that isn't
+// literally the current team id takes the full load.
+function pointsToDifferentProject(path: string): boolean {
+ if (!path.startsWith(PROJECT_PATH_PREFIX)) {
+ return false
+ }
+ const identifier = path.slice(PROJECT_PATH_PREFIX.length).split('/')[0]
+ return !!identifier && identifier !== String(getCurrentTeamIdOrNone())
+}
+
+/** Where the user should land after logging in: `?next=` when the server-side `login_required()`
+ * decorator put one there, otherwise the app root. Always same-origin. */
+function loginRedirectTarget(): string {
+ try {
+ const nextPath = getRelativeNextPath(router.values.searchParams['next'], location) || '/'
+
+ const url = new URL(location.origin + nextPath)
+ if (url.protocol === 'http:' || url.protocol === 'https:') {
+ // Note that the hash MUST be handled client-side because /login?next= is generated by the server-side
+ // `login_required()` decorator, and hash params never make it to the server
+ return url.pathname + url.search + encodeParams(router.values.hashParams, '#')
+ }
+ } catch {
+ // do nothing
+ }
+ return '/'
+}
+
+const SIGNED_OUT_PAGE_FULL_LOAD_KEY = 'ph_signed_out_page_full_load'
+const SIGNED_OUT_PAGE_FULL_LOAD_WINDOW_MS = 30_000
+
+type SignedOutPageFullLoadClaim = 'claimed' | 'repeated' | 'storage_unavailable'
+
+/** A server that keeps rendering the session signed out would send the new document straight back to
+ * /login, so a target gets one full load per window and the next attempt stays client-side. */
+function claimFullLoadFromSignedOutPage(nextURL: string): SignedOutPageFullLoadClaim {
+ try {
+ const previous = JSON.parse(window.sessionStorage.getItem(SIGNED_OUT_PAGE_FULL_LOAD_KEY) ?? 'null')
+ if (previous?.url === nextURL && Date.now() - previous.at < SIGNED_OUT_PAGE_FULL_LOAD_WINDOW_MS) {
+ return 'repeated'
+ }
+ window.sessionStorage.setItem(SIGNED_OUT_PAGE_FULL_LOAD_KEY, JSON.stringify({ url: nextURL, at: Date.now() }))
+ return 'claimed'
+ } catch {
+ // Without storage there is no loop guard, and an unguarded full load can reload forever.
+ return 'storage_unavailable'
+ }
+}
+
+/** Leave the login screen for a session that is already authenticated, e.g. someone opening
+ * `/login` in a second tab. When the app context in this document is already the logged-in one, the
+ * redirect can stay client-side. Straight after authenticating, use `redirectAfterLogin` instead. */
+export function handleLoginRedirect(): void {
+ const nextURL = loginRedirectTarget()
+
+ // The server rendered this page for a signed-out visitor, so its app context has no user and its
+ // stable chunk import map holds only the signed-out scenes. The app must arrive as a new document.
+ if (!isUserLoggedIn()) {
+ const claim = claimFullLoadFromSignedOutPage(nextURL)
+ if (claim === 'claimed') {
+ // Replace rather than assign so the stale signed-out document doesn't stay in history —
+ // otherwise Back would return to /login, or redirect into the app again.
+ window.location.replace(nextURL)
+ return
+ }
+ if (claim === 'repeated') {
+ posthog.capture('signed-out page redirect repeated')
+ } else {
+ posthog.capture('signed-out page redirect skipped', { reason: claim })
+ }
+ }
+
+ // Check if this is a backend-only route that shouldn't go through the React router
+ if (BACKEND_ONLY_ROUTES.some((route) => nextURL.startsWith(route))) {
+ window.location.href = nextURL
+ return
+ }
+
+ // A cross-project deep link needs a full page load so `AutoProjectMiddleware` can switch the
+ // active project before the scene mounts. A client-side replace would strip the project id and
+ // resolve the scene against the project we were last in, 404ing a resource that really exists.
+ if (pointsToDifferentProject(nextURL)) {
+ window.location.href = nextURL
+ return
+ }
+
+ // A safe way to redirect to a user input URL. Calls history.replaceState() ensuring the URLs origin does not change
+ router.actions.replace(nextURL)
+}
+
+/** Land on the post-login page in a single document load.
+ *
+ * `POSTHOG_APP_CONTEXT` is injected into the HTML, so a document served to a logged-out visitor
+ * still describes a logged-out one. The destination must arrive as a new document, and it takes
+ * the place of the login entry in history.
+ *
+ * An explicit destination must resolve to a same-origin path. That also rules out a bare fragment
+ * or query string. The guard falls back to `loginRedirectTarget()`, which checks `?next=` the
+ * same way. */
+export function redirectAfterLogin(destination?: string): void {
+ const guardedDestination = destination ? getRelativeNextPath(destination, location) : null
+ // Replace, so Back does not return to the login screen
+ window.location.replace(guardedDestination || loginRedirectTarget())
+}
diff --git a/frontend/src/scenes/authentication/auth/loginLogic.test.ts b/frontend/src/scenes/authentication/auth/loginLogic.test.ts
index f87ed131d645..548fba065148 100644
--- a/frontend/src/scenes/authentication/auth/loginLogic.test.ts
+++ b/frontend/src/scenes/authentication/auth/loginLogic.test.ts
@@ -4,13 +4,14 @@ import { expectLogic, testUtilsPlugin } from 'kea-test-utils'
import posthog from 'posthog-js'
import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
+import { handleLoginRedirect, redirectAfterLogin } from 'lib/utils/loginRedirect'
import { passkeyLogic } from 'scenes/authentication/shared/passkeyLogic'
import { initKea } from '~/initKea'
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
-import { handleLoginRedirect, loginLogic, redirectAfterLogin } from './loginLogic'
+import { loginLogic } from './loginLogic'
jest.mock('@simplewebauthn/browser', () => ({ startAuthentication: jest.fn() }))
jest.mock('posthog-js')
diff --git a/frontend/src/scenes/authentication/auth/loginLogic.ts b/frontend/src/scenes/authentication/auth/loginLogic.ts
index 117f77f4be13..e0ebd037f8b2 100644
--- a/frontend/src/scenes/authentication/auth/loginLogic.ts
+++ b/frontend/src/scenes/authentication/auth/loginLogic.ts
@@ -3,7 +3,7 @@ import { MakeLogicType, actions, connect, kea, listeners, path, reducers, select
import { forms } from 'kea-forms'
import type { DeepPartial, DeepPartialMap, FieldName, ValidationErrorType } from 'kea-forms'
import { loaders } from 'kea-loaders'
-import { encodeParams, urlToAction } from 'kea-router'
+import { urlToAction } from 'kea-router'
import { router } from 'kea-router'
import posthog from 'posthog-js'
@@ -14,8 +14,8 @@ import { lemonToast } from 'lib/lemon-ui/LemonToast'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { isWebKitBrowser } from 'lib/utils/dom'
-import { getCurrentTeamIdOrNone, isUserLoggedIn } from 'lib/utils/getAppContext'
-import { getRelativeNextPath, isEmail } from 'lib/utils/url'
+import { redirectAfterLogin } from 'lib/utils/loginRedirect'
+import { isEmail } from 'lib/utils/url'
import { devLoginLogic } from 'scenes/authentication/shared/devLoginLogic'
import {
clearPendingVerificationEmail,
@@ -81,125 +81,6 @@ function precheckFallback(email: string): PrecheckResponseType {
}
}
-// Routes that should be handled by Django, not the React router
-const BACKEND_ONLY_ROUTES = [
- '/login/vercel/continue',
- '/oauth/authorize',
- '/toolbar_oauth/authorize',
- '/toolbar_oauth/check',
-]
-
-const PROJECT_PATH_PREFIX = '/project/'
-
-// True when the path targets a project other than the one we're currently in. A client-side
-// history replace can't switch the active project, so `AutoProjectMiddleware` never runs and any
-// team-scoped scene resolves against the wrong project and 404s. The project segment is either a
-// numeric team id or a token (a `phc_` project key, or a legacy api_token from the middleware's
-// switching allowlist), and only the server can resolve a token to a team, so anything that isn't
-// literally the current team id takes the full load.
-function pointsToDifferentProject(path: string): boolean {
- if (!path.startsWith(PROJECT_PATH_PREFIX)) {
- return false
- }
- const identifier = path.slice(PROJECT_PATH_PREFIX.length).split('/')[0]
- return !!identifier && identifier !== String(getCurrentTeamIdOrNone())
-}
-
-/** Where the user should land after logging in: `?next=` when the server-side `login_required()`
- * decorator put one there, otherwise the app root. Always same-origin. */
-function loginRedirectTarget(): string {
- try {
- const nextPath = getRelativeNextPath(router.values.searchParams['next'], location) || '/'
-
- const url = new URL(location.origin + nextPath)
- if (url.protocol === 'http:' || url.protocol === 'https:') {
- // Note that the hash MUST be handled client-side because /login?next= is generated by the server-side
- // `login_required()` decorator, and hash params never make it to the server
- return url.pathname + url.search + encodeParams(router.values.hashParams, '#')
- }
- } catch {
- // do nothing
- }
- return '/'
-}
-
-const SIGNED_OUT_PAGE_FULL_LOAD_KEY = 'ph_signed_out_page_full_load'
-const SIGNED_OUT_PAGE_FULL_LOAD_WINDOW_MS = 30_000
-
-type SignedOutPageFullLoadClaim = 'claimed' | 'repeated' | 'storage_unavailable'
-
-/** A server that keeps rendering the session signed out would send the new document straight back to
- * /login, so a target gets one full load per window and the next attempt stays client-side. */
-function claimFullLoadFromSignedOutPage(nextURL: string): SignedOutPageFullLoadClaim {
- try {
- const previous = JSON.parse(window.sessionStorage.getItem(SIGNED_OUT_PAGE_FULL_LOAD_KEY) ?? 'null')
- if (previous?.url === nextURL && Date.now() - previous.at < SIGNED_OUT_PAGE_FULL_LOAD_WINDOW_MS) {
- return 'repeated'
- }
- window.sessionStorage.setItem(SIGNED_OUT_PAGE_FULL_LOAD_KEY, JSON.stringify({ url: nextURL, at: Date.now() }))
- return 'claimed'
- } catch {
- // Without storage there is no loop guard, and an unguarded full load can reload forever.
- return 'storage_unavailable'
- }
-}
-
-/** Leave the login screen for a session that is already authenticated, e.g. someone opening
- * `/login` in a second tab. When the app context in this document is already the logged-in one, the
- * redirect can stay client-side. Straight after authenticating, use `redirectAfterLogin` instead. */
-export function handleLoginRedirect(): void {
- const nextURL = loginRedirectTarget()
-
- // The server rendered this page for a signed-out visitor, so its app context has no user and its
- // stable chunk import map holds only the signed-out scenes. The app must arrive as a new document.
- if (!isUserLoggedIn()) {
- const claim = claimFullLoadFromSignedOutPage(nextURL)
- if (claim === 'claimed') {
- // Replace rather than assign so the stale signed-out document doesn't stay in history —
- // otherwise Back would return to /login, or redirect into the app again.
- window.location.replace(nextURL)
- return
- }
- if (claim === 'repeated') {
- posthog.capture('signed-out page redirect repeated')
- } else {
- posthog.capture('signed-out page redirect skipped', { reason: claim })
- }
- }
-
- // Check if this is a backend-only route that shouldn't go through the React router
- if (BACKEND_ONLY_ROUTES.some((route) => nextURL.startsWith(route))) {
- window.location.href = nextURL
- return
- }
-
- // A cross-project deep link needs a full page load so `AutoProjectMiddleware` can switch the
- // active project before the scene mounts. A client-side replace would strip the project id and
- // resolve the scene against the project we were last in, 404ing a resource that really exists.
- if (pointsToDifferentProject(nextURL)) {
- window.location.href = nextURL
- return
- }
-
- // A safe way to redirect to a user input URL. Calls history.replaceState() ensuring the URLs origin does not change
- router.actions.replace(nextURL)
-}
-
-/** Land on the post-login page in a single document load.
- *
- * `POSTHOG_APP_CONTEXT` is injected into the HTML, so a document served to a logged-out visitor
- * still describes a logged-out one. The destination must arrive as a new document, and it takes
- * the place of the login entry in history.
- *
- * An explicit destination must resolve to a same-origin path. That also rules out a bare fragment
- * or query string. The guard falls back to `loginRedirectTarget()`, which checks `?next=` the
- * same way. */
-export function redirectAfterLogin(destination?: string): void {
- const guardedDestination = destination ? getRelativeNextPath(destination, location) : null
- // Replace, so Back does not return to the login screen
- window.location.replace(guardedDestination || loginRedirectTarget())
-}
-
export interface LoginForm {
email: string
password: string
diff --git a/frontend/src/scenes/authentication/login-2fa/login2FALogic.ts b/frontend/src/scenes/authentication/login-2fa/login2FALogic.ts
index 3cc135e4f6ec..4965df755281 100644
--- a/frontend/src/scenes/authentication/login-2fa/login2FALogic.ts
+++ b/frontend/src/scenes/authentication/login-2fa/login2FALogic.ts
@@ -8,7 +8,7 @@ import { urlToAction } from 'kea-router'
import api, { ApiError } from 'lib/api'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { preflightLogic } from 'lib/logic/preflightLogic'
-import { redirectAfterLogin } from 'scenes/authentication/auth/loginLogic'
+import { redirectAfterLogin } from 'lib/utils/loginRedirect'
import { getPasskeyErrorMessage, isWebAuthnCancellation } from 'scenes/settings/user/passkeys/utils'
import { urls } from 'scenes/urls'
diff --git a/frontend/src/scenes/authentication/shared/PasskeyLoginButton.tsx b/frontend/src/scenes/authentication/shared/PasskeyLoginButton.tsx
new file mode 100644
index 000000000000..160b83bf1135
--- /dev/null
+++ b/frontend/src/scenes/authentication/shared/PasskeyLoginButton.tsx
@@ -0,0 +1,43 @@
+import { useActions, useValues } from 'kea'
+
+import passkeyLogo from 'lib/components/SocialLoginButton/passkey.svg'
+import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { LemonTag } from 'lib/lemon-ui/LemonTag'
+
+import { BeginPasskeyLoginParams, passkeyLogic } from './passkeyLogic'
+
+interface PasskeyLoginButtonProps {
+ isLastUsed?: boolean
+ extraQueryParams?: Record<string, string>
+}
+
+export function PasskeyLoginButton({ isLastUsed, extraQueryParams }: PasskeyLoginButtonProps): JSX.Element {
+ const { beginPasskeyLogin } = useActions(passkeyLogic)
+ const { isLoading } = useValues(passkeyLogic)
+
+ return (
+ <div className="relative">
+ <LemonButton
+ size="large"
+ icon={<img src={passkeyLogo} alt="Passkey" className="object-contain w-7 h-7" />}
+ active={isLastUsed}
+ tooltip="Passkey"
+ htmlType="button"
+ onClick={() => {
+ beginPasskeyLogin(undefined, extraQueryParams as BeginPasskeyLoginParams)
+ }}
+ loading={isLoading}
+ data-attr="passkey-login"
+ />
+ {isLastUsed && (
+ <LemonTag
+ type="muted"
+ size="small"
+ className="absolute -top-3 left-1/2 -translate-x-1/2 pointer-events-none"
+ >
+ Last used
+ </LemonTag>
+ )}
+ </div>
+ )
+}
diff --git a/frontend/src/scenes/authentication/shared/devLoginLogic.ts b/frontend/src/scenes/authentication/shared/devLoginLogic.ts
index 7f5f5f20b750..9aadfb2d2178 100644
--- a/frontend/src/scenes/authentication/shared/devLoginLogic.ts
+++ b/frontend/src/scenes/authentication/shared/devLoginLogic.ts
@@ -4,6 +4,7 @@ import { router } from 'kea-router'
import api from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast'
+import { redirectAfterLogin } from 'lib/utils/loginRedirect'
import { urls } from 'scenes/urls'
export interface DevUser {
@@ -214,7 +215,7 @@ export const devLoginLogic = kea<devLoginLogicType>([
},
devLogin: async ({ email }) => {
// Dynamic import to avoid a circular dependency: loginLogic statically imports this logic.
- const { loginLogic, redirectAfterLogin } = await import('scenes/authentication/auth/loginLogic')
+ const { loginLogic } = await import('scenes/authentication/auth/loginLogic')
loginLogic.actions.clearGeneralError()
try {
// nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. No generated function covers this endpoint yet. Find out why the generated client skips it (no schema, no product tag, or excluded from the spec) and fix that first.
diff --git a/frontend/src/scenes/authentication/shared/passkeyLogic.ts b/frontend/src/scenes/authentication/shared/passkeyLogic.ts
index b57385e65b10..e864109c5631 100644
--- a/frontend/src/scenes/authentication/shared/passkeyLogic.ts
+++ b/frontend/src/scenes/authentication/shared/passkeyLogic.ts
@@ -13,7 +13,8 @@ import api from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { apiStatusLogic } from 'lib/logic/apiStatusLogic'
import { isWebKitBrowser } from 'lib/utils/dom'
-import { loginLogic, redirectAfterLogin } from 'scenes/authentication/auth/loginLogic'
+import { redirectAfterLogin } from 'lib/utils/loginRedirect'
+import { loginLogic } from 'scenes/authentication/auth/loginLogic'
import { ssoEnforcedMessage } from 'scenes/authentication/shared/loginErrorMessages'
import { getPasskeyErrorMessage, isWebAuthnCancellation } from 'scenes/settings/user/passkeys/utils'
import { urls } from 'scenes/urls'
diff --git a/frontend/src/scenes/sceneLogic.tsx b/frontend/src/scenes/sceneLogic.tsx
index 51fb318cc13b..eca4d23c6602 100644
--- a/frontend/src/scenes/sceneLogic.tsx
+++ b/frontend/src/scenes/sceneLogic.tsx
@@ -30,6 +30,7 @@ import { markBootPhase } from 'lib/utils/bootTiming'
import { getAppContext } from 'lib/utils/getAppContext'
import { isChunkLoadError } from 'lib/utils/isChunkLoadError'
import { addProjectIdIfMissing, getProjectIdentifierInPath, removeProjectIdIfPresent } from 'lib/utils/kea-router'
+import { handleLoginRedirect } from 'lib/utils/loginRedirect'
import { retryImport } from 'lib/utils/retryImport'
import { isStableChunkBuild, reloadAfterChunkLoadError } from 'lib/utils/stableChunks'
import { identifierToHuman } from 'lib/utils/strings'
@@ -59,7 +60,6 @@ import { FileSystemIconType, ProductKey } from '~/queries/schema/schema-general'
import { loadCoreFilterDefinitions } from '~/taxonomy/loadCoreFilterDefinitions'
import { AccessControlLevel, UserType } from '~/types'
-import { handleLoginRedirect } from './authentication/auth/loginLogic'
import { parseCouponCampaign } from './coupons/utils'
import { isOnboardingRedirectSuppressed } from './onboarding/onboardingDelegationState'
import { organizationLogic } from './organizationLogic'