Skip to content

Conversation

@hexedpackets
Copy link
Contributor

Adds all missing optional parameters for these methods. Using Map.take/2 instead of explicitly listing the new map also fixes an issue where email_verified was always being sent to the API regardless of whether the caller passes it.

Closes #76

@greptile-apps
Copy link

greptile-apps bot commented Dec 30, 2025

Greptile Summary

This PR fixes two bugs in the UserManagement module and adds missing API parameters.

  • Bug Fix feat(workos-elixir): Add connection to get_authorization_url #1: create_user/2 now correctly passes the password parameter (previously the code referenced a non-existent domains field due to a typo)
  • Bug Fix 0.1.2 #2: update_user/3 no longer defaults email_verified to false when not provided. The old code used !!opts[:email_verified] which converted nil to false, causing unintended API behavior
  • Improvement: Both functions now use Map.take/2 to only include fields explicitly provided by the caller, preventing nil values from being sent to the API
  • New Parameters: Added support for password_hash, password_hash_type, external_id, metadata (both functions) and email (update_user only)
  • Tests: Added comprehensive test coverage for all new and fixed parameters

Confidence Score: 5/5

Important Files Changed

Filename Overview
lib/workos/user_management.ex Fixed create_user/2 to include password field (was incorrectly named domains) and update_user/3 to not default email_verified to false. Both now use Map.take/2 to only send provided fields.
test/workos/user_management_test.exs Added comprehensive test coverage for new parameters: password, password_hash, email update, external_id, and metadata for both create_user and update_user.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant UserManagement
    participant Client
    participant WorkOS API

    Note over Caller,WorkOS API: create_user flow (fixed)
    Caller->>UserManagement: create_user(%{email: "user@example.com", password: "secret"})
    UserManagement->>UserManagement: Map.take(opts, [:email, :password, ...])
    UserManagement->>Client: post("/user_management/users", %{email: "...", password: "..."})
    Client->>WorkOS API: POST with JSON body (only provided fields)
    WorkOS API-->>Caller: User created with password set

    Note over Caller,WorkOS API: update_user flow (fixed)
    Caller->>UserManagement: update_user(user_id, %{password: "newpass"})
    UserManagement->>UserManagement: Map.take(opts, [:password, :email_verified, ...])
    Note right of UserManagement: Only password included (email_verified omitted)
    UserManagement->>Client: put("/user_management/users/:id", %{password: "..."})
    Client->>WorkOS API: PUT with JSON body (only provided fields)
    WorkOS API-->>Caller: User updated without changing email_verified
Loading

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.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@hexedpackets hexedpackets merged commit f8b4229 into main Dec 31, 2025
4 checks passed
@hexedpackets hexedpackets deleted the user-management-updates branch December 31, 2025 18:01
@georgeguimaraes
Copy link

Thanks!

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.

create_user doesn't pass password parameter; update_user defaults email_verified incorrectly

4 participants