Skip to content

feat(auth): Add progressive invitation acceptance - #125910

Merged
evanpurkhiser merged 1 commit into
masterfrom
feat/auth-progressive-invitation-acceptance
Sep 30, 2026
Merged

evanpurkhiser merged 1 commit into
masterfrom
feat/auth-progressive-invitation-acceptance

Conversation

@evanpurkhiser

@evanpurkhiser evanpurkhiser commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Move organization invitation acceptance under the branded authentication layout and compose the invitation account badge, account authentication, and status components introduced earlier in this stack.

Signed-out users can create an account or sign in, including MFA, within the invitation screen. Authentication refreshes the invitation before presenting acceptance. Organization SSO accepts the invitation through the provider pipeline and lands in the organization. Signed-in users see the account they are accepting with and can switch accounts inline.

useInvitationFlow owns fetching, authentication completion, account switching, acceptance, and the derived view state. The page renders that state with a shared InvitationLayout, while getInvitationStep selects the authentication or acceptance step independently of the status component.

The invitation query opts into explicit acceptance. MFA enrollment in a separate tab leaves the invitation pending, and returning to the invitation refetches its requirements before offering acceptance. Temporary invitation, organization-config, and authentication-config failures show a retry action; invalid or expired invitations retain their account-switch action. A failed refresh after logout keeps the previous account hidden.

Retain the legacy invitation component and its unit tests for a follow-up cleanup.

Backend dependency: #126028 is merged and included in this stack’s base, so browser CI exercises the compatibility behavior. It preserves default automatic acceptance for existing clients while enabling explicit acceptance and preserving pending MFA challenges for this flow. Deploy that backend change before landing this frontend change.

Verification: all eight browser acceptance journeys pass using the default auth configuration against that backend: signed-in acceptance, new-account registration, password sign-in, MFA sign-in, organization SSO, switching accounts and signing in again, refreshing during a pending MFA challenge, and required MFA enrollment in a second tab followed by returning and explicitly accepting without a page reload. Registration and sign-in assert the membership remains pending before acceptance. Page integration tests cover transient-load retries, organization-config retries, failed focus refreshes, and failed refreshes after logout. The scoped frontend suite has 39 passing tests; frontend type-checking and lint checks pass.

@evanpurkhiser
evanpurkhiser requested review from a team as code owners September 29, 2026 17:39
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Sep 29, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@evanpurkhiser
evanpurkhiser removed this pull request from stack #125911 September 29, 2026 17:53
@evanpurkhiser
evanpurkhiser force-pushed the feat/auth-progressive-invitation-acceptance branch from 23e141b to d79166b Compare September 29, 2026 17:54
@evanpurkhiser
evanpurkhiser requested review from a team as code owners September 29, 2026 17:54
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 29, 2026
@evanpurkhiser
evanpurkhiser changed the base branch from git/feat-auth-authenticate-protected-organizations-in-a-modal to master September 29, 2026 17:54
@evanpurkhiser
evanpurkhiser force-pushed the feat/auth-progressive-invitation-acceptance branch from d79166b to 8820cba Compare September 29, 2026 18:15
@evanpurkhiser
evanpurkhiser changed the base branch from master to ref/auth-support-branded-top-level-routes September 29, 2026 18:15
@github-actions github-actions Bot removed the Scope: Backend Automatically applied to PRs that change backend components label Sep 29, 2026
@evanpurkhiser
evanpurkhiser removed this pull request from stack #125923 September 29, 2026 18:16

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment on lines +38 to +44
function mockInvite(body: InviteDetails | (() => InviteDetails)) {
return MockApiClient.addMockResponse({
url: '/accept-invite/org-slug/1/abc/',
method: 'GET',
body,
});
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would almost rather inline

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

const authConfigQuery = useQuery({
...authConfigQueryOptions,
enabled: needsAccountAuthentication,
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refresh wipes pending MFA state

Medium Severity

The invite GET still runs initiate_login, which deletes _pending_2fa before /auth/config/ is fetched. A refresh during inline MFA therefore loses the pending challenge and shows the registration form instead. The acceptance: 'explicit' query is sent but is not handled on the backend, so it does not skip that reset.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 38b2b2b. Configure here.

@evanpurkhiser
evanpurkhiser force-pushed the feat/auth-progressive-invitation-acceptance branch from 38b2b2b to c4b3db3 Compare September 30, 2026 14:31
evanpurkhiser added a commit that referenced this pull request Sep 30, 2026
Keep invitation acceptance compatible with the existing screen while the
composed authentication flow rolls out.

Clients can opt in with `GET
/api/0/accept-invite/{organization}/{member}/{token}/?acceptance=explicit`.
The opt-in is stored with the pending invitation in the session. MFA
enrollment then leaves that invitation pending for an explicit
acceptance POST. Clients using the default request retain automatic
acceptance after enrollment. Session cleanup removes the opt-in, and
loading another invitation with the default behavior resets it.

The opted-in request also preserves a pending MFA login challenge when
the invitation page is reloaded. Authentication and acceptance
validation remain unchanged, and organization SSO continues to accept
through its provider pipeline.

Deploy this backend change before the frontend opt-in in #125910.

Verification: 67 scoped backend tests pass, covering existing automatic
acceptance, explicit TOTP/SMS/security-key enrollment, subsequent
explicit acceptance, invalid invitations, session scoping, and pending
MFA preservation. Backend typing and lint checks pass. The composed flow
was also tested against this backend with all eight browser acceptance
journeys passing.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment on lines +58 to +65
<Alert variant="danger">{t('Unable to load this invitation. Try again.')}</Alert>
<Button
busy={state.isRetrying}
disabled={state.isRetrying}
onClick={actions.retryInvitation}
>
{t('Try again')}
</Button>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a LoadingError component or something here we can use?

evanpurkhiser added a commit that referenced this pull request Sep 30, 2026
Add the signed-in account badge used by the branded invitation flow.
Showing the account name and email helps users confirm which account
will join the organization; the parent owns account switching and
invitation refreshes.

Includes a focused interaction test and a component story. This
component lands ahead of the route change in #125910, so the existing
invitation screen remains active.
evanpurkhiser added a commit that referenced this pull request Sep 30, 2026
## Summary

Add `InvitationAuthentication`, the account-creation and sign-in step
for the composed invitation acceptance page. Invitees can authenticate
within the invitation screen, then review and explicitly accept the
invitation using the account they authenticated with.

This component composes the registration and account-authentication
forms used by the branded auth views. Keeping their form handling,
authentication requests, provider links, and MFA UI shared lets fixes to
the main authentication flow carry through to invitation acceptance.

## Flow

- Start with `RegistrationForm`, prefilled with the invitation email.
Its `secondaryAction` renders “Have an account? Sign in” using a
translated link-style button.
- Switch to `AccountAuthentication` for password sign-in and the
external-provider links supplied by `authConfig`. “Don't have an
account? Create one” returns to registration.
- When password sign-in requires MFA, keep the challenge inline and wait
for MFA completion before reporting authentication. A pending challenge
supplied by `authConfig` takes precedence over the initial registration
view, allowing the parent to restore an in-progress sign-in.
- During MFA, hide the registration switch. “Back to Login” uses the
shared MFA cancellation request and returns to password sign-in. Local
cancellation state overrides the initial pending-MFA configuration so
the canceled challenge is not immediately redisplayed.
- Animate transitions between registration, password sign-in, and MFA
using the shared motion timing.

Invitation registration remains available when public signup is
disabled; account creation continues to be authorized by the backend
invitation session.

## Component boundary

`InvitationAuthentication` owns registration/sign-in navigation and the
local MFA-method state. It receives authentication configuration and the
initial registration email from its parent.

Successful registration, password sign-in, or MFA completion calls
`onAuthenticated` with the authenticated account and destination. The
wrapper delegates the next step to the parent: the invitation page
refreshes the invitation requirements and presents acceptance.
Invitation fetching, organization SSO, account switching, acceptance,
and final navigation belong to the surrounding flow.

This PR adds the component, its focused tests, and an interactive story.
Route wiring and page orchestration are introduced in #125910, allowing
this authentication step to be reviewed independently.

## Verification

Focused component tests cover prefilled registration and navigation in
both directions, successful registration without navigation, password
sign-in and configured provider links when public signup is disabled,
MFA completion before reporting authentication, and cancellation of a
pending MFA challenge. The story documents the component's props and
demonstrates the registration/sign-in UI.
@evanpurkhiser
evanpurkhiser force-pushed the feat/auth-progressive-invitation-acceptance branch from c4b3db3 to 6e279c8 Compare September 30, 2026 14:59
@evanpurkhiser
evanpurkhiser force-pushed the feat/auth-progressive-invitation-acceptance branch from 6e279c8 to 3f88b92 Compare September 30, 2026 15:04
Comment on lines +56 to +77
self.browser.driver.execute_script(
"""
const form = document.createElement('form');
form.method = 'POST';
form.action = '/auth/sso/';

const input = document.createElement('input');
input.name = 'email';
input.value = arguments[0];
form.appendChild(input);

const csrfInput = document.createElement('input');
csrfInput.name = 'csrfmiddlewaretoken';
csrfInput.value = arguments[1];
form.appendChild(csrfInput);

document.body.appendChild(form);
form.submit();
""",
email,
csrf_cookie["value"],
)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this javascript?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can get rid of this

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a5b5c05. Configure here.

authConfig={loginConfig}
initialEmail={initialEmail}
onAuthenticated={actions.handleAuthenticated}
/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Social login abandons optional-SSO invites

Medium Severity

Social login leaves the invitation page, but optional-SSO organizations store a session next of / and this flow opts into acceptance=explicit. After Google, GitHub, or Azure authentication the user lands on / without membership and without a way to accept.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a5b5c05. Configure here.

Comment on lines +16 to +17
path: 'accept/:orgId/:memberId/:token/',
component: make(() => import('sentry/views/authV2/acceptOrganizationInvite')),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The new route path accept/:orgId/:memberId/:token/ mismatches the actual invitation URL /accept-invite/..., which will cause invitation links to result in a 404 error.
Severity: CRITICAL

Suggested Fix

In static/app/views/authV2/routes.tsx, update the route path from path: 'accept/:orgId/:memberId/:token/' to path: 'accept-invite/:orgId/:memberId/:token/' to match the URL pattern used in user invitation links.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: static/app/views/authV2/routes.tsx#L16-L17

Potential issue: The new route for accepting organization invitations is defined with
the path `accept/:orgId/:memberId/:token/`. However, the actual invitation links sent to
users, and the corresponding API endpoints, use the path prefix `/accept-invite/`. Since
the old route for `/accept-invite/` is no longer registered in the main router, users
clicking on invitation links will encounter a 404 error, preventing them from accepting
the invitation and joining the organization.

@linear-code

linear-code Bot commented Oct 15, 2026

Copy link
Copy Markdown

ISWF-1420

This branch was successfully deployed

1 active deployment
Preview — 5f1422e7 Deployed Sep 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants