Skip to content

Conversation

@petarTenderly
Copy link

Description

Add List Session Method that will call workOS API for list session

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

@petarTenderly petarTenderly requested a review from a team as a code owner October 26, 2025 20:07
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 ListSessions method to retrieve user sessions from the WorkOS API with pagination support.

  • Introduced Session struct with comprehensive fields including user/org IDs, status, auth method, IP address, timestamps
  • Created ListSessionsOpts for filtering and pagination (UserID, Limit, Before, After, Order)
  • Implemented ListSessions client method following existing patterns with proper error handling
  • Added wrapper function in usermanagement.go for default client usage
  • Included comprehensive test coverage with mock handlers

Issue found: The ListSessionsOpts struct is missing url struct tags, which means query parameters won't be properly encoded when calling the API. This will cause filtering/pagination to not work correctly.

Confidence Score: 3/5

  • Missing struct tags will prevent query parameters from working, but no security issues
  • The implementation follows existing patterns and includes proper tests, but the missing url struct tags on ListSessionsOpts is a functional bug that will prevent query parameters from being sent to the API. This needs to be fixed before merging.
  • pkg/usermanagement/client.go needs struct tags added to ListSessionsOpts (lines 618-624)

Important Files Changed

File Analysis

Filename Score Overview
pkg/usermanagement/client.go 3/5 Added Session struct, ListSessionsOpts, ListSessionsResponse, and ListSessions method; missing URL struct tags in ListSessionsOpts will cause query params to be ignored
pkg/usermanagement/client_test.go 5/5 Added listSessionsTestHandler test handler following existing test patterns
pkg/usermanagement/usermanagement.go 5/5 Added ListSessions wrapper function that delegates to DefaultClient.ListSessions
pkg/usermanagement/usermanagement_test.go 5/5 Added TestUserManagementListSessions test using standard patterns from existing tests

Sequence Diagram

sequenceDiagram
    participant Client as Application
    participant UM as usermanagement.ListSessions()
    participant DC as DefaultClient
    participant API as WorkOS API
    
    Client->>UM: ListSessions(ctx, opts)
    UM->>DC: DefaultClient.ListSessions(ctx, opts)
    DC->>DC: Create HTTP GET request to /user_management/sessions
    DC->>DC: Set default Limit=10 if opts.Limit==0
    DC->>DC: Set default Order=Desc if opts.Order==""
    DC->>DC: Encode opts to query params using query.Values()
    DC->>API: GET /user_management/sessions?query_params
    Note over DC,API: Headers: Authorization, User-Agent, Content-Type
    API-->>DC: ListSessionsResponse (JSON)
    DC->>DC: Decode JSON response
    DC-->>UM: ListSessionsResponse
    UM-->>Client: ListSessionsResponse
Loading

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link
Contributor

@mattgd mattgd left a comment

Choose a reason for hiding this comment

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

Thanks for opening this PR - left a few comments. Feel free to tag me when ready for re-review.

@petarTenderly petarTenderly requested a review from mattgd November 16, 2025 16:08
@petarTenderly
Copy link
Author

@mattgd Hi Matt, its ready for review

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