Skip to content

Conversation

@mnemitz
Copy link
Contributor

@mnemitz mnemitz 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.

Copy link

@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

This PR enhances the AuthKit-Remix library by exposing the organizationId field in the onSuccess callback of the auth loader. The change adds the organizationId field (type string | null) to the AuthLoaderSuccessData interface and modifies the callback route handler to pass this value through from the WorkOS userManagement response. This enables applications to access organization information immediately after successful authentication, supporting workflows like initializing organization data during user signup when an organization context is needed.

The change integrates cleanly with the existing codebase architecture, following the established pattern of nullable organization IDs used throughout other interfaces. The modification allows applications to perform organization-specific setup logic without requiring additional API calls to retrieve this information.

Important Files Changed

Filename Score Overview
src/interfaces.ts 5/5 Added organizationId: string | null field to AuthLoaderSuccessData interface
src/authkit-callback-route.ts 5/5 Modified to destructure and pass organizationId from WorkOS response to onSuccess callback

Confidence score: 5/5

  • This PR is safe to merge with minimal risk
  • Score reflects simple, well-scoped changes that follow existing patterns and maintain backward compatibility
  • No files require special attention

Sequence Diagram

sequenceDiagram
    participant User
    participant Browser
    participant RemixApp
    participant AuthLoader
    participant WorkOS
    participant SessionStorage

    User->>Browser: "Clicks sign-in/sign-up link"
    Browser->>RemixApp: "GET /auth/callback?code=xyz&state=abc"
    RemixApp->>AuthLoader: "loader({ request })"
    
    AuthLoader->>AuthLoader: "Extract code and state from URL params"
    AuthLoader->>WorkOS: "authenticateWithCode({ clientId, code })"
    WorkOS-->>AuthLoader: "{ accessToken, refreshToken, user, impersonator, oauthTokens, organizationId }"
    
    AuthLoader->>AuthLoader: "Clean up URL params (remove code, state)"
    AuthLoader->>AuthLoader: "Parse returnPathname from state"
    AuthLoader->>AuthLoader: "encryptSession({ accessToken, refreshToken, user, impersonator })"
    
    AuthLoader->>SessionStorage: "getSession(cookieName)"
    SessionStorage-->>AuthLoader: "session"
    AuthLoader->>SessionStorage: "session.set('jwt', encryptedSession)"
    AuthLoader->>SessionStorage: "commitSession(session)"
    SessionStorage-->>AuthLoader: "cookie"
    
    alt onSuccess callback exists
        AuthLoader->>AuthLoader: "onSuccess({ accessToken, impersonator, oauthTokens, refreshToken, user, organizationId })"
    end
    
    AuthLoader-->>RemixApp: "redirect(url, { headers: { 'Set-Cookie': cookie } })"
    RemixApp-->>Browser: "302 Redirect with session cookie"
    Browser->>User: "Redirected to returnPathname"
Loading

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@gcarvelli gcarvelli merged commit 9370e47 into workos:main Nov 5, 2025
3 of 5 checks passed
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.

3 participants