Skip to content

Adopt createGuest's server-issued identity for guest users#1704

Open
aleksandar-apostolov wants to merge 1 commit into
aleksandarapostolov/and-1202-guest-user-type-is-brokenfrom
aleksandarapostolov/and-1202-adopt-response-user
Open

Adopt createGuest's server-issued identity for guest users#1704
aleksandar-apostolov wants to merge 1 commit into
aleksandarapostolov/and-1202-guest-user-type-is-brokenfrom
aleksandarapostolov/and-1202-adopt-response-user

Conversation

@aleksandar-apostolov
Copy link
Copy Markdown
Contributor

@aleksandar-apostolov aleksandar-apostolov commented Jun 3, 2026

Stacked on #1703. Merge after parent.

Goal

Refs AND-1202 — keep the SDK's in-memory guest user in sync with the server-issued identity returned by createGuest, matching the JS SDK's connectUser(response.user, response.access_token) semantics.

The SDK previously discarded response.user and only kept response.accessToken. If the server resolves a guest id to a different value than what the integrator passed in, the WS auth payload (built from client.user.id) and the JWT user_id claim drift apart.

Implementation

  • setupGuestUser now maps response.user via UserResponse.toUser(), re-applies UserType.Guest, and writes the result back to StreamVideoClient.user.
  • StreamVideoClient.user becomes var; userId becomes get() = user.id so every reader (CallState, ParticipantState, ringing-state checks) picks up the new identity.
  • CoordinatorSocketConnection.user becomes var, set from the connectData/data argument inside connect()/reconnect() so onCreated()'s WS auth payload reflects the latest user.

Testing

  • New tests in StreamVideoClientTest:
    • userId tracks the current user reference — the computed property.
    • setupGuestUser adopts the server-issued user identity on success — drives setupGuestUser with a mocked api.createGuest returning a different id; asserts client.user.id, client.userId, and preserved UserType.Guest.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed guest user identity synchronization to correctly adopt server-issued credentials, preventing potential identity mismatches after guest account creation.
    • Improved user identity tracking to dynamically reflect the current user state rather than a fixed value captured at initial connection.

@aleksandar-apostolov aleksandar-apostolov added the pr:improvement Enhances an existing feature or code label Jun 3, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled, or the PR is bot-authored.
  • An issue is linked (Linear ticket or GitHub issue), or the PR is bot-authored.

🎉 Great job! This PR is ready for review.

@aleksandar-apostolov aleksandar-apostolov force-pushed the aleksandarapostolov/and-1202-guest-user-type-is-broken branch from ba62c23 to f13c6a4 Compare June 3, 2026 07:50
…y in sync

The createGuest endpoint returns the server-resolved user (which may differ
from what was passed in — e.g. normalized id). The SDK previously kept only
the access token and left its in-memory user as the builder's input, so the
WS auth payload and the JWT user_id claim could disagree.

setupGuestUser now also updates client.user from response.user (matching the
JS SDK's connectUser(response.user, response.access_token) semantics).
userId becomes a computed property so every existing reader of client.userId
picks up the new identity automatically. CoordinatorSocketConnection.user
turns into a var so its onCreated() auth payload reads the latest user.

Adds three regression tests: userId reactivity, the var update inside the
socket connection's connect path, and a full setupGuestUser flow with the
api mocked to return a different user id than the input.

AND-1202
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 3, 2026

SDK Size Comparison 📏

SDK Before After Difference Status
stream-video-android-core 12.21 MB 12.21 MB 0.00 MB 🟢
stream-video-android-ui-xml 5.68 MB 5.68 MB 0.00 MB 🟢
stream-video-android-ui-compose 6.28 MB 6.28 MB 0.00 MB 🟢

@aleksandar-apostolov aleksandar-apostolov force-pushed the aleksandarapostolov/and-1202-adopt-response-user branch from 2638910 to 63ccca2 Compare June 3, 2026 07:52
@aleksandar-apostolov aleksandar-apostolov marked this pull request as ready for review June 3, 2026 07:55
@aleksandar-apostolov aleksandar-apostolov requested a review from a team as a code owner June 3, 2026 07:55
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4a84fa8b-0fd4-4609-b8d1-b4870e6cf222

📥 Commits

Reviewing files that changed from the base of the PR and between f13c6a4 and 63ccca2.

📒 Files selected for processing (3)
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoClient.kt
  • stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/coordinator/CoordinatorSocketConnection.kt
  • stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/StreamVideoClientTest.kt

Walkthrough

The PR updates StreamVideoClient and CoordinatorSocketConnection to use mutable user properties, enabling the client to adopt a server-issued user identity after guest creation. StreamVideoClient.userId is now a computed getter reflecting the current user.id. New tests validate that userId updates dynamically and that setupGuestUser correctly adopts server responses.

Changes

Guest user identity adoption with mutable user properties

Layer / File(s) Summary
StreamVideoClient user property mutability
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoClient.kt
Imports toUser and UserType helpers. Changes user from immutable (val) to mutable (var). Updates userId to a computed getter that always reflects current user.id.
Guest user adoption in setupGuestUser
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoClient.kt
After successful guest creation, setupGuestUser replaces the client's user with the server-provided identity from createGuest response, converted via toUser and tagged as UserType.Guest.
CoordinatorSocketConnection user property mutability
stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/socket/coordinator/CoordinatorSocketConnection.kt
Changes user from immutable (val) to mutable (var). Updates connect and reconnect to assign the incoming user before delegating to internalSocket methods.
Test validation for user identity mutations
stream-video-android-core/src/test/kotlin/io/getstream/video/android/core/StreamVideoClientTest.kt
Adds test imports for generated API models and mocking. Adds regression test verifying userId reflects current user.id dynamically. Adds test verifying setupGuestUser adopts server-issued user identity with correct type.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🐰 A guest arrives with server's blessing,
Their user flows like water through the app,
No more static, just dynamic blessing—
Mutable users close the identity gap! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adopting the server-issued identity from createGuest responses for guest users, which directly aligns with the primary objective to fix identity drift.
Description check ✅ Passed The description covers the required sections: Goal (with linear issue reference), Implementation (detailed changes to StreamVideoClient, CoordinatorSocketConnection, and setupGuestUser), and Testing (specific test cases added). While UI Changes and the Contributor/Reviewer checklists are not applicable to this backend-focused change, the core required information is present and comprehensive.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch aleksandarapostolov/and-1202-adopt-response-user

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 3, 2026

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

Labels

pr:improvement Enhances an existing feature or code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant