Skip to content

Conversation

@nicknisi
Copy link
Member

@nicknisi nicknisi commented Nov 5, 2025

This PR allows the organizationId returned the userManagement call to be returned directly to the onSuccess callback.

This can help enable flows such as initializing an organization for a user where not present on signup.

This is a port of workos/authkit-remix#80.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

Added organizationId to the onSuccess callback data in the authentication flow, enabling developers to access the organization ID immediately after successful authentication.

Changes:

  • Extracted organizationId from WorkOS authenticateWithCode response
  • Added organizationId: string | null to AuthLoaderSuccessData interface
  • Passed organizationId to the onSuccess callback handler

Impact:
This change enables use cases like initializing organization data for new users during signup. The implementation is consistent with the existing pattern used in RefreshSuccessOptions interface (line 39 in src/interfaces.ts) and follows the same null-coalescing pattern used for other optional fields like impersonator and oauthTokens.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are straightforward and consistent with existing patterns in the codebase. The organizationId field is already used throughout the codebase in interfaces like RefreshSuccessOptions, UserInfo, and AuthorizedData. The implementation follows the same null-coalescing pattern (?? null) used for other optional fields. No security concerns, no breaking changes, and no custom instruction violations.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
src/authkit-callback-route.ts 5/5 Added organizationId extraction from authentication response and passed it to onSuccess callback
src/interfaces.ts 5/5 Added `organizationId: string

Sequence Diagram

sequenceDiagram
    participant Client
    participant AuthLoader
    participant WorkOS
    participant OnSuccess
    participant Session
    
    Client->>AuthLoader: GET /callback?code=xxx&state=xxx
    AuthLoader->>WorkOS: authenticateWithCode(clientId, code)
    WorkOS-->>AuthLoader: {accessToken, refreshToken, user, impersonator, oauthTokens, organizationId}
    AuthLoader->>AuthLoader: encryptSession({accessToken, refreshToken, user, impersonator})
    AuthLoader->>Session: commitSession(encrypted session)
    Session-->>AuthLoader: cookie
    AuthLoader->>OnSuccess: onSuccess({accessToken, refreshToken, user, impersonator, oauthTokens, organizationId})
    OnSuccess-->>AuthLoader: void
    AuthLoader-->>Client: 302 Redirect with Set-Cookie header
Loading

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@nicknisi nicknisi changed the title feat: add organiationId to onSuccess callback feat: add organizationId to onSuccess callback Nov 5, 2025
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