Skip to content

Invitation token persistence#68

Draft
southgate wants to merge 3 commits intomainfrom
cursor/invitation-token-persistence-00d7
Draft

Invitation token persistence#68
southgate wants to merge 3 commits intomainfrom
cursor/invitation-token-persistence-00d7

Conversation

@southgate
Copy link

Implement invitation token persistence to prevent users from losing their invitation during password reset flows.

This fixes a bug where the invitation_token would be lost if a user initiated a password reset before accepting an invitation, leading to the JWT missing custom claims. The token is now captured and stored securely in an httpOnly cookie, then reused upon successful authentication.


Slack Thread

Open in Web Open in Cursor 

This fix addresses the issue where users lose their invitation token when
they reset their password during the invitation acceptance flow.

Changes:
- Add invitation token persistence utility that stores the token in a
  httpOnly cookie when a user lands with ?invitation_token= in the URL
- Add InvitationTokenCapture component in the root layout to automatically
  capture and store invitation tokens from URL parameters
- Update all authentication methods (email/password, magic auth, OAuth,
  SSO) to check for and use stored invitation tokens
- Token is automatically consumed (deleted) after being used in an
  authentication request

This ensures that if a user:
1. Receives an invitation with invitation_token in URL
2. Clicks to accept but forgets their password
3. Resets their password
4. Signs in after password reset

The invitation token will still be available to accept the invitation
and properly set up their organization membership and custom JWT claims.

Co-authored-by: Alex Southgate <southgate@users.noreply.github.com>
@cursor
Copy link

cursor bot commented Mar 2, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursoragent and others added 2 commits March 2, 2026 17:10
- Add Jest testing framework setup
- Add unit tests for invitation-token utility functions
- Add tests for InvitationTokenCapture component
- Add flow simulation tests verifying token persistence

All 14 tests passing.

Co-authored-by: Alex Southgate <southgate@users.noreply.github.com>
This endpoint allows testing the invitation token cookie flow:
- Store, get, consume, and clear operations
- Useful for verifying the fix works in development

Note: Consider removing or protecting this endpoint in production.

Co-authored-by: Alex Southgate <southgate@users.noreply.github.com>
@linear
Copy link

linear bot commented Mar 4, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants