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.

feat(auth): open login tools by default on the dev login screen (#75943)

Michael Matlokac619184f2c99
diff --git a/frontend/src/scenes/authentication/shared/devLoginLogic.ts b/frontend/src/scenes/authentication/shared/devLoginLogic.ts
index 9af059d3d4ce..4e448f4d2542 100644
--- a/frontend/src/scenes/authentication/shared/devLoginLogic.ts
+++ b/frontend/src/scenes/authentication/shared/devLoginLogic.ts
@@ -6,18 +6,19 @@ import { lemonToast } from 'lib/lemon-ui/LemonToast'
export interface DevUser {
email: string
+ first_name: string
is_staff: boolean
label: string | null
+ last_login: string | null
}
export const DEV_LOGIN_SECONDS_SAVED_PER_CLICK = 5
-export const DEV_LOGIN_DEFAULT_EMAIL = '[email protected]'
-
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface devLoginLogicValues {
createFreshAccountLoading: boolean
devLoginCount: number
+ devLoginPanelOpen: boolean
devLoginTimeSavedLabel: string | null
devUsers: DevUser[]
devUsersLoading: boolean
@@ -52,6 +53,9 @@ export interface devLoginLogicActions {
devUsers: DevUser[]
payload?: any
}
+ setDevLoginPanelOpen: (open: boolean) => {
+ open: boolean
+ }
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -75,6 +79,7 @@ export const devLoginLogic = kea<devLoginLogicType>([
createFreshAccount: true,
createFreshAccountSuccess: true,
createFreshAccountFailure: (error: string) => ({ error }),
+ setDevLoginPanelOpen: (open: boolean) => ({ open }),
}),
reducers({
devLoginCount: [
@@ -84,6 +89,15 @@ export const devLoginLogic = kea<devLoginLogicType>([
devLogin: (count) => count + 1,
},
],
+ // Open out of the box — the panel is the fastest way into a local instance. Persisted so
+ // that closing it sticks for anyone who'd rather type credentials.
+ devLoginPanelOpen: [
+ true,
+ { persist: true },
+ {
+ setDevLoginPanelOpen: (_, { open }) => open,
+ },
+ ],
createFreshAccountLoading: [
false,
{
@@ -97,18 +111,14 @@ export const devLoginLogic = kea<devLoginLogicType>([
devUsers: [
[] as DevUser[],
{
- // Not fired on an `onMount` because we don't always need it.
+ // Not fired on an `onMount` because we don't always need it. The whole list comes
+ // down in one go — this only ever runs against a local instance.
loadDevUsers: async (_, breakpoint) => {
breakpoint()
try {
const response = await api.get<{ users: DevUser[] }>('api/login/dev')
- // Pin the default seeded user to the top; the rest keep the backend's alphabetical order.
- const users = [...response.users]
- const defaultIndex = users.findIndex((u) => u.email === DEV_LOGIN_DEFAULT_EMAIL)
- if (defaultIndex > 0) {
- users.unshift(...users.splice(defaultIndex, 1))
- }
- return users
+ breakpoint()
+ return response.users
} catch {
// Endpoint is unavailable unless allow_dev_login is set in preflight.
return []
diff --git a/frontend/src/scenes/authentication/shared/paperDesk/DevLoginPanel.stories.tsx b/frontend/src/scenes/authentication/shared/paperDesk/DevLoginPanel.stories.tsx
index 044134d3847a..44f6fcf552e5 100644
--- a/frontend/src/scenes/authentication/shared/paperDesk/DevLoginPanel.stories.tsx
+++ b/frontend/src/scenes/authentication/shared/paperDesk/DevLoginPanel.stories.tsx
@@ -3,6 +3,7 @@ import type { Meta, StoryFn } from '@storybook/react'
import { useStorybookMocks } from '~/mocks/browser'
import preflightJson from '~/mocks/fixtures/_preflight.json'
+import type { DevUser } from '../devLoginLogic'
import { DevLoginPanel } from './DevLoginPanel'
type StoryArgs = {
@@ -10,35 +11,45 @@ type StoryArgs = {
devUsers: 'none' | 'default' | 'many'
}
-const DEV_USERS_MOCKS = {
- none: { users: [] },
- default: {
- users: [
- {
- email: '[email protected]',
- is_staff: true,
- label: 'Default test user',
- },
- { email: '[email protected]', is_staff: true, label: null },
- ],
- },
- many: {
- users: [
- {
- email: '[email protected]',
- is_staff: true,
- label: 'Default test user',
- },
- { email: '[email protected]', is_staff: true, label: null },
- { email: '[email protected]', is_staff: true, label: 'Admin' },
- { email: '[email protected]', is_staff: false, label: null },
- {
- email: '[email protected]',
+const DEV_USERS_MOCKS: Record<StoryArgs['devUsers'], DevUser[]> = {
+ none: [],
+ default: [
+ {
+ email: '[email protected]',
+ first_name: 'Test',
+ is_staff: true,
+ label: 'Default test user',
+ last_login: '2026-07-31T09:00:00Z',
+ },
+ { email: '[email protected]', first_name: 'Staff', is_staff: true, label: null, last_login: null },
+ {
+ email: '[email protected]',
+ first_name: 'Longwinded',
+ is_staff: false,
+ label: null,
+ last_login: null,
+ },
+ ],
+ // The growth team's local instances look like this: hundreds of throwaway signup test accounts.
+ many: [
+ {
+ email: '[email protected]',
+ first_name: 'Test',
+ is_staff: true,
+ label: 'Default test user',
+ last_login: '2026-07-31T09:00:00Z',
+ },
+ ...Array.from({ length: 320 }, (_, index): DevUser => {
+ const firstName = ['Ada', 'Byron', 'Cleo', 'Dorian', 'Edith', 'Felix', 'Greta'][index % 7]
+ return {
+ email: `${firstName.toLowerCase()}-${String(index).padStart(4, '0')}@posthog.dev`,
+ first_name: firstName,
is_staff: false,
- label: 'New',
- },
- ],
- },
+ label: null,
+ last_login: index < 5 ? `2026-07-3${index}T09:00:00Z` : null,
+ }
+ }),
+ ],
}
const meta: Meta<StoryArgs> = {
@@ -71,7 +82,7 @@ const Template: StoryFn<StoryArgs> = ({ allowDevLogin, devUsers }) => {
is_debug: true,
allow_dev_login: allowDevLogin,
},
- '/api/login/dev': DEV_USERS_MOCKS[devUsers],
+ '/api/login/dev': { users: DEV_USERS_MOCKS[devUsers] },
},
})
diff --git a/frontend/src/scenes/authentication/shared/paperDesk/DevLoginPanel.tsx b/frontend/src/scenes/authentication/shared/paperDesk/DevLoginPanel.tsx
index 11db01c4c9e5..6caad8ffb79b 100644
--- a/frontend/src/scenes/authentication/shared/paperDesk/DevLoginPanel.tsx
+++ b/frontend/src/scenes/authentication/shared/paperDesk/DevLoginPanel.tsx
@@ -1,127 +1,146 @@
import { useActions, useValues } from 'kea'
-import { useEffect, useState } from 'react'
+import { useEffect } from 'react'
+import { IconPlus, IconX } from '@posthog/icons'
+
+import { dayjs } from 'lib/dayjs'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
+import { Lettermark } from 'lib/lemon-ui/Lettermark'
+import { Spinner } from 'lib/lemon-ui/Spinner'
import { OAUTH_REGIONS } from 'lib/oauth/oauthClient'
import { oauthLogic } from 'lib/oauth/oauthLogic'
+import { hashCodeForString } from 'lib/utils/strings'
import { preflightLogic } from 'scenes/PreflightCheck/preflightLogic'
import { Region } from '~/types'
-import { devLoginLogic } from '../devLoginLogic'
-
-// The panel holds a scrollable list of dev users that can grow very long locally,
-// so cap it to roughly half the viewport height (minus the fixed sections).
-const DEV_USERS_LIST_MAX_HEIGHT = 'max-h-[45vh]'
+import { DevUser, devLoginLogic } from '../devLoginLogic'
/** Floating dev-only panel (top-right) combining dev-login shortcuts and OAuth prod-data login. */
export function DevLoginPanel(): JSX.Element | null {
const { preflight } = useValues(preflightLogic)
- const { devUsers, devUsersLoading, createFreshAccountLoading } = useValues(devLoginLogic)
- const { devLogin, loadDevUsers, createFreshAccount } = useActions(devLoginLogic)
+ const { devUsers, devUsersLoading, devLoginPanelOpen, createFreshAccountLoading } = useValues(devLoginLogic)
+ const { devLogin, loadDevUsers, createFreshAccount, setDevLoginPanelOpen } = useActions(devLoginLogic)
const { loginInProgress } = useValues(oauthLogic)
const { beginLogin } = useActions(oauthLogic)
- const [open, setOpen] = useState(false)
const isDebug = !!preflight?.is_debug
const allowDevLogin = !!preflight?.allow_dev_login
useEffect(() => {
- if (allowDevLogin && open) {
+ if (allowDevLogin && devLoginPanelOpen) {
loadDevUsers(null)
}
- }, [allowDevLogin, open, loadDevUsers])
+ }, [allowDevLogin, devLoginPanelOpen, loadDevUsers])
if (!isDebug) {
return null
}
- const showDevLogin = allowDevLogin && !devUsersLoading && devUsers.length > 0
+ if (!devLoginPanelOpen) {
+ return (
+ <div className="fixed top-4 right-4 z-50">
+ <LemonButton size="small" type="tertiary" onClick={() => setDevLoginPanelOpen(true)}>
+ Login tools
+ </LemonButton>
+ </div>
+ )
+ }
return (
- <div className="fixed top-4 right-4 z-50">
- {open ? (
- <div className={`w-64 bg-white border rounded shadow p-3 flex flex-col ${DEV_USERS_LIST_MAX_HEIGHT}`}>
- <div className="flex items-center justify-between mb-3">
- <span className="text-xs font-semibold text-muted">Login tools</span>
- <button type="button" className="text-muted" onClick={() => setOpen(false)} aria-label="Close">
- ✕
- </button>
- </div>
- <div className="flex-1 overflow-y-auto min-h-0">
- {showDevLogin && (
- <div className="mb-4">
- <p className="text-xs font-medium text-muted mb-1.5">Login as</p>
- <div className="flex flex-col gap-1">
- {devUsers.map((u) => (
- <button
- key={u.email}
- type="button"
- onClick={() => devLogin(u.email)}
- data-attr={`dev-login-${u.email}`}
- className="flex items-center gap-2 w-full text-left px-2.5 py-1.5 rounded border border-border bg-bg-light hover:border-accent hover:bg-accent-highlight transition-colors"
- >
- <span className="flex-1 truncate text-xs">{u.email}</span>
- {u.label && <span className="text-xs text-muted">{u.label}</span>}
- </button>
- ))}
- </div>
- </div>
- )}
- {showDevLogin && <div className="border-t border-border my-3" />}
- {allowDevLogin && (
- <div className="mb-4">
- <p className="text-xs font-medium text-muted mb-1.5">Onboarding testing</p>
- <button
- type="button"
- disabled={createFreshAccountLoading}
- onClick={createFreshAccount}
- data-attr="dev-create-fresh-account"
- className="flex items-center gap-2 w-full text-left px-2.5 py-1.5 rounded border border-border bg-bg-light hover:border-accent hover:bg-accent-highlight disabled:opacity-50 disabled:hover:border-border disabled:hover:bg-bg-light transition-colors"
- >
- <span className="flex-1 text-xs">
- {createFreshAccountLoading
- ? 'Creating account…'
- : 'Create fresh account & start onboarding'}
- </span>
- </button>
- <p className="text-xs text-muted mt-1">
- Random account + org (password: 12345678), lands you straight in onboarding.
- </p>
- </div>
- )}
- <div>
- <p className="text-xs font-medium text-muted mb-1.5">Login via OAuth</p>
- <div className="flex flex-col gap-1">
- <button
- type="button"
- disabled={loginInProgress}
- onClick={() => beginLogin(Region.US)}
- data-attr="dev-oauth-us"
- className="flex items-center gap-2 w-full text-left px-2.5 py-1.5 rounded border border-border bg-bg-light hover:border-accent hover:bg-accent-highlight disabled:opacity-50 disabled:hover:border-border disabled:hover:bg-bg-light transition-colors"
- >
- <span className="text-base leading-none">{OAUTH_REGIONS[Region.US].flag}</span>
- <span className="text-xs">US Cloud</span>
- </button>
- <button
- type="button"
- disabled={loginInProgress}
- onClick={() => beginLogin(Region.EU)}
- data-attr="dev-oauth-eu"
- className="flex items-center gap-2 w-full text-left px-2.5 py-1.5 rounded border border-border bg-bg-light hover:border-accent hover:bg-accent-highlight disabled:opacity-50 disabled:hover:border-border disabled:hover:bg-bg-light transition-colors"
- >
- <span className="text-base leading-none">{OAUTH_REGIONS[Region.EU].flag}</span>
- <span className="text-xs">EU Cloud</span>
- </button>
- </div>
+ <div className="PaperDesk__card fixed top-4 right-4 z-50 flex flex-col w-72 max-w-[calc(100vw-2rem)] max-h-[calc(100vh-2rem)]">
+ <div className="flex items-center justify-between gap-2 pl-3 pr-1.5 py-1.5 border-b border-[#e0e1d9]">
+ <span className="text-xs font-semibold text-muted">Login tools</span>
+ <LemonButton
+ size="xsmall"
+ icon={<IconX />}
+ onClick={() => setDevLoginPanelOpen(false)}
+ tooltip="Hide login tools"
+ aria-label="Hide login tools"
+ />
+ </div>
+ {allowDevLogin && (
+ <div className="flex-1 min-h-0 max-h-[45vh] overflow-y-auto p-1.5">
+ {devUsers.map((user) => (
+ <DevUserButton key={user.email} user={user} onClick={devLogin} />
+ ))}
+ {devUsersLoading && (
+ <div className="flex justify-center py-4">
+ <Spinner />
</div>
- </div>
+ )}
+ {!devUsersLoading && devUsers.length === 0 && (
+ <p className="text-xs text-muted text-center px-2 py-4 m-0">
+ No accounts yet. Create a fresh demo account below.
+ </p>
+ )}
</div>
- ) : (
- <LemonButton size="small" type="tertiary" onClick={() => setOpen(true)}>
- Login tools
- </LemonButton>
)}
+ <div className="flex flex-col gap-2 px-3 py-2.5 border-t border-[#e0e1d9]">
+ {allowDevLogin && (
+ <LemonButton
+ type="secondary"
+ size="small"
+ fullWidth
+ center
+ icon={<IconPlus />}
+ loading={createFreshAccountLoading}
+ disabledReason={createFreshAccountLoading ? 'Creating account' : undefined}
+ onClick={createFreshAccount}
+ data-attr="dev-create-fresh-account"
+ tooltip="Creates a throwaway account and organization with a random name and the password 12345678, then opens onboarding."
+ >
+ Create fresh demo account
+ </LemonButton>
+ )}
+ <div>
+ <p className="text-xs font-medium text-muted mb-1">Log in via OAuth</p>
+ <div className="grid grid-cols-2 gap-1">
+ {([Region.US, Region.EU] as const).map((region) => (
+ <LemonButton
+ key={region}
+ type="secondary"
+ size="small"
+ fullWidth
+ center
+ disabledReason={loginInProgress ? 'Login in progress' : undefined}
+ onClick={() => beginLogin(region)}
+ data-attr={`dev-oauth-${region.toLowerCase()}`}
+ icon={<span className="text-base leading-none">{OAUTH_REGIONS[region].flag}</span>}
+ >
+ {region === Region.US ? 'US Cloud' : 'EU Cloud'}
+ </LemonButton>
+ ))}
+ </div>
+ </div>
+ </div>
</div>
)
}
+
+function DevUserButton({ user, onClick }: { user: DevUser; onClick: (email: string) => void }): JSX.Element {
+ const subtitle = user.label || (user.is_staff ? 'Staff' : user.first_name)
+ // Color the lettermark off the email rather than list position, so an account keeps the same
+ // one as the list reorders by recency.
+ const colorIndex = hashCodeForString(user.email)
+ return (
+ <LemonButton
+ size="small"
+ fullWidth
+ onClick={() => onClick(user.email)}
+ data-attr={`dev-login-${user.email}`}
+ icon={<Lettermark name={user.first_name || user.email} index={colorIndex} size="small" rounded />}
+ sideIcon={
+ user.last_login ? (
+ <span className="text-xs text-muted whitespace-nowrap">{dayjs(user.last_login).fromNow(true)}</span>
+ ) : undefined
+ }
+ tooltip={user.email}
+ >
+ <span className="flex flex-col min-w-0 py-0.5">
+ <span className="text-xs truncate">{user.email}</span>
+ {subtitle && <span className="text-xs text-muted truncate font-normal">{subtitle}</span>}
+ </span>
+ </LemonButton>
+ )
+}
diff --git a/frontend/src/scenes/authentication/shared/paperDesk/PaperDesk.scss b/frontend/src/scenes/authentication/shared/paperDesk/PaperDesk.scss
index 030613376f93..9e066d9d57a7 100644
--- a/frontend/src/scenes/authentication/shared/paperDesk/PaperDesk.scss
+++ b/frontend/src/scenes/authentication/shared/paperDesk/PaperDesk.scss
@@ -25,6 +25,16 @@
16px 16px;
}
+// Paper sheet resting on the desk — the login card and the dev login panel share it.
+.PaperDesk__card {
+ background: #fff;
+ border: 1px solid #e0e1d9;
+ border-radius: var(--radius-lg);
+ box-shadow:
+ 0 20px 44px -26px rgb(40 38 30 / 35%),
+ 0 3px 0 #e0e1d9;
+}
+
// Child SVG sizing — child selector, no Tailwind equivalent
.PaperDesk__logo {
svg {
diff --git a/frontend/src/scenes/authentication/shared/paperDesk/PaperDeskScene.tsx b/frontend/src/scenes/authentication/shared/paperDesk/PaperDeskScene.tsx
index 780bb47980f2..752accc59663 100644
--- a/frontend/src/scenes/authentication/shared/paperDesk/PaperDeskScene.tsx
+++ b/frontend/src/scenes/authentication/shared/paperDesk/PaperDeskScene.tsx
@@ -41,9 +41,7 @@ export function PaperDeskCard({
) : (
top
)}
- <div className="w-full pt-8 px-5 sm:px-9 pb-8 bg-white border border-[#e0e1d9] rounded-lg shadow-[0_20px_44px_-26px_rgb(40_38_30/35%),0_3px_0_#e0e1d9]">
- {children}
- </div>
+ <div className="PaperDesk__card w-full pt-8 px-5 sm:px-9 pb-8">{children}</div>
{footer}
</>
)
diff --git a/posthog/api/authentication.py b/posthog/api/authentication.py
index fd10535372e9..c3529b73fb66 100644
--- a/posthog/api/authentication.py
+++ b/posthog/api/authentication.py
@@ -20,6 +20,7 @@ from django.contrib.auth.views import redirect_to_login
from django.core.exceptions import ValidationError
from django.core.signing import BadSignature
from django.db import transaction
+from django.db.models import F, Q
from django.http import Http404, HttpRequest, HttpResponse, JsonResponse
from django.shortcuts import redirect
from django.utils import timezone
@@ -31,6 +32,7 @@ from axes.exceptions import AxesBackendPermissionDenied
from axes.handlers.proxy import AxesProxyHandler
from django_otp import login as otp_login
from django_otp.plugins.otp_static.models import StaticDevice
+from drf_spectacular.utils import extend_schema
from loginas.utils import is_impersonated_session, restore_original_login
from rest_framework import mixins, permissions, serializers, status, viewsets
from rest_framework.decorators import action
@@ -574,6 +576,25 @@ class DevLoginSerializer(serializers.Serializer):
return user
+class DevLoginUserSerializer(serializers.Serializer):
+ email = serializers.EmailField(read_only=True, help_text="Email to log in as.")
+ first_name = serializers.CharField(read_only=True, help_text="First name, shown next to the email.")
+ is_staff = serializers.BooleanField(read_only=True, help_text="Whether the user is a staff (instance admin) user.")
+ # Shadows Field.label, which the metaclass moves aside into _declared_fields at runtime.
+ label = serializers.CharField( # type: ignore[assignment]
+ read_only=True, allow_null=True, help_text="Label for accounts seeded by setup_dev, e.g. the default test user."
+ )
+ last_login = serializers.DateTimeField(
+ read_only=True, allow_null=True, help_text="When this account was last logged in as, or null if never."
+ )
+
+
+class DevLoginUserListSerializer(serializers.Serializer):
+ users = DevLoginUserSerializer(
+ many=True, read_only=True, help_text="Every active user, seeded accounts first, then most recently used."
+ )
+
+
class DevLoginViewSet(NonCreatingViewSetMixin, viewsets.GenericViewSet):
"""
Dev-only convenience endpoint. Lists active users and lets the login UI
@@ -585,11 +606,20 @@ class DevLoginViewSet(NonCreatingViewSetMixin, viewsets.GenericViewSet):
serializer_class = DevLoginSerializer
permission_classes = (permissions.AllowAny,)
+ @extend_schema(responses={200: DevLoginUserListSerializer})
def list(self, request: Request) -> Response:
if not is_dev_login_allowed():
raise Http404()
- users = list(User.objects.filter(is_active=True).order_by("email").values("email", "is_staff")[:50])
+ # Seeded accounts first so the default test user stays on top. After that recency beats
+ # alphabetical: on instances with hundreds of test accounts, the handful you actually
+ # switch between float up on their own. Email breaks ties to keep the order stable.
+ users = list(
+ User.objects.filter(is_active=True)
+ .annotate(is_seeded=Q(email__in=DEV_LOGIN_KNOWN_EMAIL_LABELS))
+ .order_by("-is_seeded", F("last_login").desc(nulls_last=True), "email")
+ .values("email", "first_name", "is_staff", "last_login")
+ )
for entry in users:
entry["label"] = DEV_LOGIN_KNOWN_EMAIL_LABELS.get(entry["email"])
diff --git a/posthog/api/test/test_authentication.py b/posthog/api/test/test_authentication.py
index 00599c7870c7..1853d4b13df9 100644
--- a/posthog/api/test/test_authentication.py
+++ b/posthog/api/test/test_authentication.py
@@ -440,6 +440,20 @@ class TestDevLoginAPI(APIBaseTest):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.json(), {"success": True})
+ @override_settings(DEBUG=True, ALLOW_DEV_LOGIN=True)
+ def test_dev_login_list_puts_seeded_then_recently_used_accounts_first(self):
+ User.objects.create_and_join(self.organization, "[email protected]", None)
+ recently_used = User.objects.create_and_join(self.organization, "[email protected]", None)
+ recently_used.last_login = timezone.now()
+ recently_used.save()
+ # Seeded by setup_dev, and never logged in as — it still belongs on top.
+ User.objects.create_and_join(self.organization, "[email protected]", None)
+
+ response = self.client.get("/api/login/dev")
+ self.assertEqual(response.status_code, status.HTTP_200_OK)
+ emails = [user["email"] for user in response.json()["users"]]
+ self.assertEqual(emails[:2], ["[email protected]", "[email protected]"])
+
@override_settings(DEBUG=True, ALLOW_DEV_LOGIN=False)
def test_dev_login_hidden_when_allow_dev_login_disabled(self):
response = self.client.get("/api/login/dev")