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(provisioning): explain the verify-email stop on partner deep links (#97086)

posthog[bot]eb715224e595
diff --git a/ee/api/agentic_provisioning/analytics.py b/ee/api/agentic_provisioning/analytics.py
index 496c98f7ab2d..3b1d260cf783 100644
--- a/ee/api/agentic_provisioning/analytics.py
+++ b/ee/api/agentic_provisioning/analytics.py
@@ -34,7 +34,8 @@ def capture_provisioning_event(
def capture_deep_link_event(outcome: str, **extra: object) -> None:
- capture_provisioning_event("deep link login", outcome, partner=None, **extra)
+ # Pinned: the Stripe namespace captures this step under the same name, so both surfaces share a funnel.
+ capture_provisioning_event("deep_link_login", outcome, partner=None, **extra)
def capture_auth_event(app: OAuthApplication, outcome: str, **extra: object) -> None:
diff --git a/ee/api/agentic_provisioning/constants.py b/ee/api/agentic_provisioning/constants.py
index 9424747e3ef8..d569f0a5a45a 100644
--- a/ee/api/agentic_provisioning/constants.py
+++ b/ee/api/agentic_provisioning/constants.py
@@ -17,6 +17,9 @@ DEEP_LINK_MAX_PATH_LENGTH = 2000
# building blocks of header-injection and backslash-host open-redirect tricks, so reject them outright.
DEEP_LINK_DISALLOWED_PATH_CHARS = re.compile(r"[\x00-\x20\x7f-\x9f\\]")
+# Pinned: the verify-email scene matches this exact value to pick the copy it shows.
+VERIFY_EMAIL_REASON = "partner_deep_link"
+
CIMD_DOMAIN_RATE_LIMIT_PREFIX = "cimd_registration_domain_rate:"
CIMD_DOMAIN_RATE_LIMIT_MAX = 5
CIMD_DOMAIN_RATE_LIMIT_WINDOW_SECONDS = 3600
diff --git a/ee/api/agentic_provisioning/test/test_deep_links.py b/ee/api/agentic_provisioning/test/test_deep_links.py
index 08ec28c86b9b..69db3aeb0fed 100644
--- a/ee/api/agentic_provisioning/test/test_deep_links.py
+++ b/ee/api/agentic_provisioning/test/test_deep_links.py
@@ -216,7 +216,8 @@ class TestAgenticLogin(ProvisioningTestBase):
("null_legacy", None),
]
)
- def test_unverified_user_redirects_to_verify_email(self, _name, verified_value):
+ @patch("ee.api.agentic_provisioning.views.deep_links.email_verification_code_verifier.send_code")
+ def test_unverified_user_redirects_to_verify_email(self, _name, verified_value, _mock_send_code):
# Both False (new partner account) and None (legacy NULL passthrough) must be
# blocked - deep-link login has no password challenge.
self.user.is_email_verified = verified_value
@@ -224,7 +225,19 @@ class TestAgenticLogin(ProvisioningTestBase):
token = self._create_deep_link_token()
res = self.client.get(f"/agentic/login?token={token}")
assert res.status_code == 302
- assert res["Location"] == f"/verify_email/{self.user.uuid}"
+ assert res["Location"] == f"/verify_email/{self.user.uuid}?reason=partner_deep_link"
+
+ @patch(
+ "ee.api.agentic_provisioning.views.deep_links.email_verification_code_verifier.send_code",
+ side_effect=Exception("smtp down"),
+ )
+ def test_failed_verification_email_is_flagged_to_the_page(self, _mock_send_code):
+ self.user.is_email_verified = False
+ self.user.save(update_fields=["is_email_verified"])
+ token = self._create_deep_link_token()
+ res = self.client.get(f"/agentic/login?token={token}")
+ assert res.status_code == 302
+ assert res["Location"] == f"/verify_email/{self.user.uuid}?reason=partner_deep_link&email_sent=false"
def test_unverified_user_does_not_create_session(self):
self.user.is_email_verified = False
diff --git a/ee/api/agentic_provisioning/views/deep_links.py b/ee/api/agentic_provisioning/views/deep_links.py
index 55cfbe856345..04a56d672756 100644
--- a/ee/api/agentic_provisioning/views/deep_links.py
+++ b/ee/api/agentic_provisioning/views/deep_links.py
@@ -12,7 +12,7 @@ from django.core.cache import cache
from django.http import HttpResponseRedirect
from django.http.response import HttpResponseBase
from django.utils import timezone
-from django.utils.http import url_has_allowed_host_and_scheme
+from django.utils.http import url_has_allowed_host_and_scheme, urlencode
import structlog
from rest_framework.request import Request
@@ -31,6 +31,7 @@ from ee.api.agentic_provisioning.constants import (
DEEP_LINK_DISALLOWED_PATH_CHARS,
DEEP_LINK_MAX_PATH_LENGTH,
DEEP_LINK_TTL_SECONDS,
+ VERIFY_EMAIL_REASON,
)
from ee.api.agentic_provisioning.exceptions import ProvisioningError
from ee.api.agentic_provisioning.ratelimits import BLOCKED, rate_limited
@@ -190,15 +191,7 @@ def agentic_login(request: Any) -> HttpResponseBase:
# Require explicit is_email_verified=True - don't trust the legacy None passthrough
# or the org-level email-verification-disabled flag.
if user.is_email_verified is not True:
- try:
- email_verification_code_verifier.send_code(user)
- except Exception:
- # Intentionally swallowed: the login must stay blocked regardless of email delivery.
- # The verifier captures the exception internally; the verify_email page has a resend button.
- logger.warning("agentic_login.verification_email_failed", user_id=user.id)
- capture_deep_link_event("email_unverified", user_id=user_id)
- logger.warning("agentic_login.email_unverified", user_id=user_id)
- return HttpResponseRedirect(f"/verify_email/{user.uuid}")
+ return _block_unverified_email(user)
auth_login(request, user, backend="django.contrib.auth.backends.ModelBackend")
@@ -209,6 +202,26 @@ def agentic_login(request: Any) -> HttpResponseBase:
return HttpResponseRedirect(redirect_path)
+def _block_unverified_email(user: User) -> HttpResponseBase:
+ """Send a fresh code and redirect to the verify-email page, telling it why the login stopped."""
+ email_sent = True
+ try:
+ email_verification_code_verifier.send_code(user)
+ except Exception:
+ # Intentionally swallowed: the login must stay blocked regardless of email delivery.
+ # The verifier captures the exception internally; the verify_email page has a resend button.
+ email_sent = False
+ logger.warning("agentic_login.verification_email_failed", user_id=user.id)
+
+ capture_deep_link_event("email_unverified", user_id=user.id, verification_email_sent=email_sent)
+ logger.warning("agentic_login.email_unverified", user_id=user.id, email_sent=email_sent)
+
+ params: dict[str, str] = {"reason": VERIFY_EMAIL_REASON}
+ if not email_sent:
+ params["email_sent"] = "false"
+ return HttpResponseRedirect(f"/verify_email/{user.uuid}?{urlencode(params)}")
+
+
def _deep_link_redirect_path(purpose: str, team_id: int | None, path: str | None = None) -> str:
if path and is_safe_deep_link_path(path):
return path
diff --git a/ee/partners/stripe/api/provisioning/constants.py b/ee/partners/stripe/api/provisioning/constants.py
index 1b3b450bfc85..3b7c9d69b6c9 100644
--- a/ee/partners/stripe/api/provisioning/constants.py
+++ b/ee/partners/stripe/api/provisioning/constants.py
@@ -15,6 +15,9 @@ DEEP_LINK_MAX_PATH_LENGTH = 2000
# building blocks of header-injection and backslash-host open-redirect tricks, so reject them outright.
DEEP_LINK_DISALLOWED_PATH_CHARS = re.compile(r"[\x00-\x20\x7f-\x9f\\]")
+# Pinned: the verify-email scene matches this exact value to pick the copy it shows.
+VERIFY_EMAIL_REASON = "stripe_deep_link"
+
ACCESS_TOKEN_EXPIRY_SECONDS = 365 * 24 * 3600
# Default scopes for a Stripe-issued token when the auth code requested none.
diff --git a/ee/partners/stripe/api/provisioning/login.py b/ee/partners/stripe/api/provisioning/login.py
index 2d9144b37e4a..a43ac462478a 100644
--- a/ee/partners/stripe/api/provisioning/login.py
+++ b/ee/partners/stripe/api/provisioning/login.py
@@ -17,6 +17,7 @@ from typing import Any
from django.contrib.auth import login as auth_login
from django.core.cache import cache
from django.http import HttpResponseBase, HttpResponseRedirect
+from django.utils.http import urlencode
import structlog
@@ -27,15 +28,48 @@ from posthog.models.user import User
from ee.partners.stripe.api.provisioning import DEEP_LINK_CACHE_PREFIX
from ee.partners.stripe.api.provisioning.analytics import capture_provisioning_event
+from ee.partners.stripe.api.provisioning.constants import VERIFY_EMAIL_REASON
from ee.partners.stripe.api.provisioning.core import is_safe_deep_link_path
logger = structlog.get_logger(__name__)
def _capture(
- outcome: str, *, user_id: int | None = None, team_id: int | None = None, purpose: str | None = None
+ outcome: str,
+ *,
+ user_id: int | None = None,
+ team_id: int | None = None,
+ purpose: str | None = None,
+ verification_email_sent: bool | None = None,
) -> None:
- capture_provisioning_event("deep_link_login", outcome, user_id=user_id, team_id=team_id, purpose=purpose)
+ capture_provisioning_event(
+ "deep_link_login",
+ outcome,
+ user_id=user_id,
+ team_id=team_id,
+ purpose=purpose,
+ verification_email_sent=verification_email_sent,
+ )
+
+
+def _block_unverified_email(user: User) -> HttpResponseBase:
+ """Send a fresh code and redirect to the verify-email page, telling it why the login stopped."""
+ email_sent = True
+ try:
+ email_verification_code_verifier.send_code(user)
+ except Exception:
+ # Intentionally swallowed: the login must stay blocked regardless of email delivery.
+ # The verifier captures the exception internally; the verify_email page has a resend button.
+ email_sent = False
+ logger.warning("stripe_provisioning.login.verification_email_failed", user_id=user.id)
+
+ _capture("email_unverified", user_id=user.id, verification_email_sent=email_sent)
+ logger.warning("stripe_provisioning.login.email_unverified", user_id=user.id, email_sent=email_sent)
+
+ params: dict[str, str] = {"reason": VERIFY_EMAIL_REASON}
+ if not email_sent:
+ params["email_sent"] = "false"
+ return HttpResponseRedirect(f"/verify_email/{user.uuid}?{urlencode(params)}")
def _redirect_path(team_id: int | None, path: str | None) -> str:
@@ -108,15 +142,7 @@ def stripe_provisioning_login(request: Any) -> HttpResponseBase:
# Require explicit is_email_verified=True - don't trust the legacy None passthrough
# or the org-level email-verification-disabled flag.
if user.is_email_verified is not True:
- try:
- email_verification_code_verifier.send_code(user)
- except Exception:
- # Intentionally swallowed: the login must stay blocked regardless of email delivery.
- # The verifier captures the exception internally; the verify_email page has a resend button.
- logger.warning("stripe_provisioning.login.verification_email_failed", user_id=user.id)
- _capture("email_unverified", user_id=user_id)
- logger.warning("stripe_provisioning.login.email_unverified", user_id=user_id)
- return HttpResponseRedirect(f"/verify_email/{user.uuid}")
+ return _block_unverified_email(user)
auth_login(request, user, backend="django.contrib.auth.backends.ModelBackend")
diff --git a/ee/partners/stripe/api/provisioning/test/test_deep_links.py b/ee/partners/stripe/api/provisioning/test/test_deep_links.py
index 4bd631cacb19..c9cc75bd892c 100644
--- a/ee/partners/stripe/api/provisioning/test/test_deep_links.py
+++ b/ee/partners/stripe/api/provisioning/test/test_deep_links.py
@@ -1,13 +1,26 @@
from urllib.parse import parse_qs, urlparse
+from unittest.mock import patch
+
+from django.core.cache import cache
+
from parameterized import parameterized
+from ee.partners.stripe.api.provisioning import DEEP_LINK_CACHE_PREFIX
from ee.partners.stripe.api.provisioning.test.base import BASE_PATH, StripeProvisioningTestBase
DEEP_LINKS_URL = f"{BASE_PATH}/provisioning/deep_links"
+LOGIN_URL = f"{BASE_PATH}/login"
class TestDeepLinks(StripeProvisioningTestBase):
+ def _cache_deep_link_token(self, token: str) -> None:
+ cache.set(
+ f"{DEEP_LINK_CACHE_PREFIX}{token}",
+ {"user_id": self.user.id, "team_id": self.team.id},
+ timeout=600,
+ )
+
def test_deep_link_logs_the_user_in_via_agentic_login(self):
token = self._get_bearer_token()
res = self._post_signed_with_bearer(
@@ -33,6 +46,37 @@ class TestDeepLinks(StripeProvisioningTestBase):
assert me.status_code == 200
assert me.json()["email"] == self.user.email
+ @parameterized.expand(
+ [
+ ("false", False),
+ ("null_legacy", None),
+ ]
+ )
+ @patch("ee.partners.stripe.api.provisioning.login.email_verification_code_verifier.send_code")
+ def test_unverified_user_lands_on_verify_email_with_a_reason(self, _name, verified_value, _mock_send_code):
+ self.user.is_email_verified = verified_value
+ self.user.save(update_fields=["is_email_verified"])
+ self._cache_deep_link_token("stripe_unverified_token")
+
+ res = self.client.get(f"{LOGIN_URL}?token=stripe_unverified_token")
+
+ assert res.status_code == 302
+ assert res["Location"] == f"/verify_email/{self.user.uuid}?reason=stripe_deep_link"
+
+ @patch(
+ "ee.partners.stripe.api.provisioning.login.email_verification_code_verifier.send_code",
+ side_effect=Exception("smtp down"),
+ )
+ def test_failed_verification_email_is_flagged_to_the_page(self, _mock_send_code):
+ self.user.is_email_verified = False
+ self.user.save(update_fields=["is_email_verified"])
+ self._cache_deep_link_token("stripe_send_failure_token")
+
+ res = self.client.get(f"{LOGIN_URL}?token=stripe_send_failure_token")
+
+ assert res.status_code == 302
+ assert res["Location"] == f"/verify_email/{self.user.uuid}?reason=stripe_deep_link&email_sent=false"
+
def test_deep_link_refused_when_the_application_cannot_issue_them(self):
self.stripe_app.update_provisioning(can_issue_deep_links=False)
token = self._get_bearer_token()
diff --git a/frontend/src/scenes/authentication/verify-email/VerifyEmail.stories.tsx b/frontend/src/scenes/authentication/verify-email/VerifyEmail.stories.tsx
index 28a385beaf36..f6101e376724 100644
--- a/frontend/src/scenes/authentication/verify-email/VerifyEmail.stories.tsx
+++ b/frontend/src/scenes/authentication/verify-email/VerifyEmail.stories.tsx
@@ -5,12 +5,14 @@ import { useStorybookMocks } from '~/mocks/browser'
import preflightJson from '~/mocks/fixtures/_preflight.json'
import { VerifyEmail } from './VerifyEmail'
-import { verifyEmailLogic } from './verifyEmailLogic'
+import { type VerifyEmailReason, verifyEmailLogic } from './verifyEmailLogic'
type VerifyEmailView = 'pending' | 'success' | 'invalid'
type StoryArgs = {
view: VerifyEmailView
+ reason?: VerifyEmailReason
+ verificationEmailSent?: boolean
}
const meta: Meta<StoryArgs> = {
@@ -26,14 +28,24 @@ const meta: Meta<StoryArgs> = {
name: 'View',
options: ['pending', 'success', 'invalid'] satisfies VerifyEmailView[],
},
+ reason: {
+ control: 'select',
+ name: 'Deep link reason',
+ options: [undefined, 'stripe_deep_link', 'partner_deep_link'],
+ },
+ verificationEmailSent: {
+ control: 'boolean',
+ name: 'Verification email sent',
+ },
},
args: {
view: 'pending',
+ verificationEmailSent: true,
},
}
export default meta
-const Template: StoryFn<StoryArgs> = ({ view }) => {
+const Template: StoryFn<StoryArgs> = ({ view, reason, verificationEmailSent = true }) => {
useStorybookMocks({
get: {
'/_preflight': { ...preflightJson },
@@ -44,7 +56,8 @@ const Template: StoryFn<StoryArgs> = ({ view }) => {
useEffect(() => {
verifyEmailLogic.actions.setView(view)
verifyEmailLogic.actions.setUuid('12345678')
- }, [view])
+ verifyEmailLogic.actions.setDeepLinkContext(reason ?? null, verificationEmailSent)
+ }, [view, reason, verificationEmailSent])
return <VerifyEmail />
}
@@ -59,3 +72,9 @@ Success.args = { view: 'success' }
export const Invalid: StoryFn<StoryArgs> = Template.bind({})
Invalid.args = { view: 'invalid' }
+
+export const PendingFromStripeDeepLink: StoryFn<StoryArgs> = Template.bind({})
+PendingFromStripeDeepLink.args = { view: 'pending', reason: 'stripe_deep_link' }
+
+export const PendingWithFailedSend: StoryFn<StoryArgs> = Template.bind({})
+PendingWithFailedSend.args = { view: 'pending', reason: 'stripe_deep_link', verificationEmailSent: false }
diff --git a/frontend/src/scenes/authentication/verify-email/VerifyEmailForm.tsx b/frontend/src/scenes/authentication/verify-email/VerifyEmailForm.tsx
index ef51521de2f5..7565d9cda9f8 100644
--- a/frontend/src/scenes/authentication/verify-email/VerifyEmailForm.tsx
+++ b/frontend/src/scenes/authentication/verify-email/VerifyEmailForm.tsx
@@ -7,6 +7,7 @@ import * as magnifyingGlassPng from '@posthog/brand/hoggies/png/magnifying-glass
import { pngHoggie } from 'lib/brand/hoggies'
import { SleepingHog } from 'lib/components/hedgehogs'
import { supportLogic } from 'lib/components/Support/supportLogic'
+import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { Link } from 'lib/lemon-ui/Link'
import { AuthScene, AuthSceneCard } from 'scenes/authentication/shared/authScene/AuthScene'
@@ -14,13 +15,14 @@ import { getPendingVerificationEmail, isValidVerificationCode } from 'scenes/aut
import { VerificationCodeInput } from 'scenes/authentication/shared/VerificationCodeInput'
import { urls } from 'scenes/urls'
-import { verifyEmailLogic } from './verifyEmailLogic'
+import { type VerifyEmailReason, verifyEmailLogic } from './verifyEmailLogic'
const HedgehogMagnifyingGlass = pngHoggie(magnifyingGlassPng)
const HedgehogExplorer = pngHoggie(explorerPng)
const NOTES: Record<string, string[]> = {
pending: ['// one email away', '// we just hit send'],
+ send_failed: ['// the email did not go', '// give it another send'],
success: ['// verified', '// go explore'],
invalid: ['// nothing to verify', "// let's start again"],
}
@@ -31,6 +33,12 @@ const CHECKLIST = [
'Channel your inner hedgehog and peek again',
]
+const DEEP_LINK_NOTICE: Record<VerifyEmailReason, string> = {
+ stripe_deep_link:
+ "Stripe sent you to PostHog to set up analytics. Verify your email and we'll open your new project.",
+ partner_deep_link: "Your sign-in link needs a verified email. Verify it and we'll take you where you were going.",
+}
+
function NotSeeingIt(): JSX.Element {
const { openSupportForm } = useActions(supportLogic)
const { requestVerificationCode } = useActions(verifyEmailLogic)
@@ -159,16 +167,58 @@ function VerificationCodeEntry(): JSX.Element {
)
}
-export function VerifyEmailForm(): JSX.Element {
- const { view, uuid, user } = useValues(verifyEmailLogic)
- const { openSupportForm } = useActions(supportLogic)
+function CheckYourInbox(): JSX.Element {
+ const { uuid, user, reason, verificationEmailSent } = useValues(verifyEmailLogic)
- const notes = NOTES[view ?? 'pending'] ?? NOTES.pending
// The address that received the code. This is the new address if an email change is pending,
// else the account address. Without a session, for example on a fresh signup, the page uses the
// address the signup or login form stored in this browser. It stays unset in a different browser.
const verificationEmail = user?.pending_email ?? user?.email ?? getPendingVerificationEmail(uuid) ?? undefined
+ return (
+ <div className="flex flex-col items-center text-center">
+ {reason && (
+ <LemonBanner type="info" className="w-full mb-4 text-left">
+ {DEEP_LINK_NOTICE[reason]}
+ </LemonBanner>
+ )}
+ {!verificationEmailSent && (
+ <LemonBanner type="warning" className="w-full mb-4 text-left">
+ We couldn't send your code just now. Open "Not seeing it?" below to send a new one.
+ </LemonBanner>
+ )}
+ <HedgehogMagnifyingGlass className="block w-auto mx-auto h-28" />
+ <h1 className="m-0 mt-3 font-title text-2xl font-extrabold leading-tight text-primary text-center tracking-tight">
+ {verificationEmailSent ? 'Check your inbox' : 'Enter your code'}
+ </h1>
+ <p className="AuthScene__sub mt-2 mb-4 text-sm text-secondary text-center text-pretty">
+ {!verificationEmailSent ? (
+ <>Already have a code? Enter it below. Codes are valid for 30 minutes.</>
+ ) : verificationEmail ? (
+ <>
+ We sent a 6-digit code to <strong>{verificationEmail}</strong>.
+ <br />
+ It's valid for 30 minutes.
+ </>
+ ) : (
+ <>We sent you a 6-digit code. It's valid for 30 minutes.</>
+ )}
+ </p>
+ <VerificationCodeEntry />
+ <div className="mt-3">
+ <NotSeeingIt />
+ </div>
+ </div>
+ )
+}
+
+export function VerifyEmailForm(): JSX.Element {
+ const { view, verificationEmailSent } = useValues(verifyEmailLogic)
+ const { openSupportForm } = useActions(supportLogic)
+
+ const noteKey = view === 'pending' && !verificationEmailSent ? 'send_failed' : (view ?? 'pending')
+ const notes = NOTES[noteKey] ?? NOTES.pending
+
if (view === 'success') {
return (
<AuthScene notes={notes}>
@@ -254,27 +304,7 @@ export function VerifyEmailForm(): JSX.Element {
</p>
}
>
- <div className="flex flex-col items-center text-center">
- <HedgehogMagnifyingGlass className="block w-auto mx-auto h-28" />
- <h1 className="m-0 mt-3 font-title text-2xl font-extrabold leading-tight text-primary text-center tracking-tight">
- Check your inbox
- </h1>
- <p className="AuthScene__sub mt-2 mb-4 text-sm text-secondary text-center text-pretty">
- {verificationEmail ? (
- <>
- We sent a 6-digit code to <strong>{verificationEmail}</strong>.
- <br />
- It's valid for 30 minutes.
- </>
- ) : (
- <>We sent you a 6-digit code. It's valid for 30 minutes.</>
- )}
- </p>
- <VerificationCodeEntry />
- <div className="mt-3">
- <NotSeeingIt />
- </div>
- </div>
+ <CheckYourInbox />
</AuthSceneCard>
</AuthScene>
)
diff --git a/frontend/src/scenes/authentication/verify-email/verifyEmailLogic.test.ts b/frontend/src/scenes/authentication/verify-email/verifyEmailLogic.test.ts
new file mode 100644
index 000000000000..248e545f615d
--- /dev/null
+++ b/frontend/src/scenes/authentication/verify-email/verifyEmailLogic.test.ts
@@ -0,0 +1,43 @@
+import { router } from 'kea-router'
+import { expectLogic } from 'kea-test-utils'
+
+import { initKeaTests } from '~/test/init'
+
+import { verifyEmailLogic } from './verifyEmailLogic'
+
+describe('verifyEmailLogic', () => {
+ let logic: ReturnType<typeof verifyEmailLogic.build>
+
+ beforeEach(() => {
+ initKeaTests()
+ logic = verifyEmailLogic()
+ logic.mount()
+ })
+
+ afterEach(() => {
+ logic.unmount()
+ })
+
+ it('reads the deep-link reason the login redirect sent', async () => {
+ router.actions.push('/verify_email/abc-123', { reason: 'stripe_deep_link' })
+
+ await expectLogic(logic).toMatchValues({
+ view: 'pending',
+ uuid: 'abc-123',
+ reason: 'stripe_deep_link',
+ verificationEmailSent: true,
+ })
+ })
+
+ it.each([['unknown_partner'], ['']])('ignores a reason it does not know: %s', async (reason) => {
+ router.actions.push('/verify_email/abc-123', { reason })
+
+ await expectLogic(logic).toMatchValues({ reason: null })
+ })
+
+ it('flags a verification email the login could not send', async () => {
+ router.actions.push('/verify_email/abc-123', { reason: 'stripe_deep_link', email_sent: 'false' })
+
+ await expectLogic(logic).toMatchValues({ verificationEmailSent: false })
+ })
+})
diff --git a/frontend/src/scenes/authentication/verify-email/verifyEmailLogic.ts b/frontend/src/scenes/authentication/verify-email/verifyEmailLogic.ts
index ccb8eea64a54..c2942d196209 100644
--- a/frontend/src/scenes/authentication/verify-email/verifyEmailLogic.ts
+++ b/frontend/src/scenes/authentication/verify-email/verifyEmailLogic.ts
@@ -66,14 +66,25 @@ export interface VerificationResultType {
uuid?: string
}
+// Pinned: the deep-link login views send these exact values as the `reason` search param
+// (ee/partners/stripe/api/provisioning/constants.py, ee/api/agentic_provisioning/constants.py).
+export type VerifyEmailReason = 'stripe_deep_link' | 'partner_deep_link'
+
+const VERIFY_EMAIL_REASONS: VerifyEmailReason[] = ['stripe_deep_link', 'partner_deep_link']
+
+const parseVerifyEmailReason = (value: unknown): VerifyEmailReason | null =>
+ VERIFY_EMAIL_REASONS.find((reason) => reason === value) ?? null
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface verifyEmailLogicValues {
user: UserType | null // userLogic
newlyRequestedVerificationCode: boolean | null
newlyRequestedVerificationCodeLoading: boolean
+ reason: VerifyEmailReason | null
uuid: string | null
verificationCode: string
verificationCodeError: string | null
+ verificationEmailSent: boolean
verificationResult: VerificationResultType | null
verificationResultLoading: boolean
view: 'invalid' | 'pending' | 'success' | null
@@ -102,6 +113,13 @@ export interface verifyEmailLogicActions {
uuid: string
}
}
+ setDeepLinkContext: (
+ reason: VerifyEmailReason | null,
+ verificationEmailSent: boolean
+ ) => {
+ reason: VerifyEmailReason | null
+ verificationEmailSent: boolean
+ }
setUuid: (uuid: string | null) => {
uuid: string | null
}
@@ -145,6 +163,10 @@ export const verifyEmailLogic = kea<verifyEmailLogicType>([
actions({
setView: (view: 'pending' | 'invalid' | 'success' | null) => ({ view }),
setUuid: (uuid: string | null) => ({ uuid }),
+ setDeepLinkContext: (reason: VerifyEmailReason | null, verificationEmailSent: boolean) => ({
+ reason,
+ verificationEmailSent,
+ }),
requestVerificationCode: (uuid: string) => ({ uuid }),
setVerificationCode: (code: string) => ({ code }),
setVerificationCodeError: (error: string | null) => ({ error }),
@@ -219,6 +241,20 @@ export const verifyEmailLogic = kea<verifyEmailLogicType>([
setUuid: (_, { uuid }) => uuid,
},
],
+ reason: [
+ null as VerifyEmailReason | null,
+ {
+ setDeepLinkContext: (_, { reason }) => reason,
+ },
+ ],
+ verificationEmailSent: [
+ true,
+ {
+ setDeepLinkContext: (_, { verificationEmailSent }) => verificationEmailSent,
+ requestVerificationCodeSuccess: (state, { newlyRequestedVerificationCode }) =>
+ newlyRequestedVerificationCode || state,
+ },
+ ],
verificationCode: [
'',
{
@@ -235,9 +271,13 @@ export const verifyEmailLogic = kea<verifyEmailLogicType>([
],
}),
urlToAction(({ actions }) => {
- const showCodeEntry = ({ uuid }: { uuid?: string }): void => {
+ const showCodeEntry = ({ uuid }: { uuid?: string }, searchParams: Record<string, any>): void => {
if (uuid) {
actions.setUuid(uuid)
+ actions.setDeepLinkContext(
+ parseVerifyEmailReason(searchParams.reason),
+ searchParams.email_sent !== 'false'
+ )
actions.setView('pending')
}
}