Skip to content

feat(auth2): Add AuthSuccess model - #3712

Merged
tp merged 2 commits into
serverpod:mainfrom
tp:auth-session-auth-success
Jun 26, 2025
Merged

tp merged 2 commits into
serverpod:mainfrom
tp:auth-session-auth-success

Conversation

@tp

@tp tp commented Jun 25, 2025 •

Copy link
Copy Markdown
Contributor

To be returned from a successful login, instead of just the String sessionKey

This additionally contains the authUserId and scopes.

This will be used in the client "session manager" for serverpod_auth_session, where it will be really useful to have the auth user ID and scopes available for a logged-in user. (In #3721)

Summary by CodeRabbit

  • New Features

    • Introduced a new authentication result object that provides session key, user ID, and granted scopes after login and registration actions.
  • Bug Fixes

    • Updated authentication methods to return detailed session information instead of just a session key.
  • Tests

    • Adjusted test cases to use the new authentication result object and updated variable naming for clarity.
  • Documentation

    • Improved documentation to reflect changes in authentication method responses.

@coderabbitai

coderabbitai Bot commented Jun 25, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes introduce a new AuthSuccess model to encapsulate authentication results, replacing previous String session key returns in authentication methods across server and test code. Method signatures, return types, and related test assignments are updated to use AuthSuccess, and the new model is exported for external use. No internal logic or control flow is altered.

Changes

File(s) Change Summary
.../serverpod_auth_email_server/lib/src/endpoints/email_account_endpoint.dart Updated authentication method return types from Future<String> to Future<AuthSuccess> and updated documentation.
.../serverpod_auth_session_server/lib/src/business/auth_sessions.dart Changed AuthSessions.createSession return type from Future<String> to Future<AuthSuccess>.
.../serverpod_auth_session_server/lib/src/models/auth_success.spy.yaml Added new AuthSuccess model with sessionKey, authUserId, and scopeNames fields.
.../serverpod_auth_session_server/lib/serverpod_auth_session_server.dart Exported AuthSuccess in addition to existing exports.
.../serverpod_auth_session_server/test/integration/auth_sessions_authentication_handler_test.dart Updated test assignments to extract .sessionKey from returned AuthSuccess objects.
.../serverpod_auth_session_server/test/integration/auth_sessions_destroy_test.dart Updated test assignments to extract .sessionKey from returned AuthSuccess objects.
.../serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart Updated tests to use authSuccess.sessionKey instead of direct session key assignment.
.../serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart Updated method signatures and type annotations to use AuthSuccess and adjusted import aliases accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant EmailAccountEndpoint
    participant AuthSessions
    participant Database

    Client->>EmailAccountEndpoint: login(email, password)
    EmailAccountEndpoint->>AuthSessions: createSession(authUserId, ...)
    AuthSessions->>Database: Store session
    Database-->>AuthSessions: Session stored
    AuthSessions-->>EmailAccountEndpoint: AuthSuccess(sessionKey, authUserId, scopeNames)
    EmailAccountEndpoint-->>Client: AuthSuccess(sessionKey, authUserId, scopeNames)
Loading
sequenceDiagram
    participant Client
    participant EmailAccountEndpoint

    Client->>EmailAccountEndpoint: finishRegistration(accountRequestId, verificationCode)
    EmailAccountEndpoint-->>Client: AuthSuccess(sessionKey, authUserId, scopeNames)

    Client->>EmailAccountEndpoint: finishPasswordReset(passwordResetRequestId, verificationCode, newPassword)
    EmailAccountEndpoint-->>Client: AuthSuccess(sessionKey, authUserId, scopeNames)
Loading

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a8d5fe6 and b02ea95.

⛔ Files ignored due to path filters (5)
  • modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_client/lib/src/protocol/auth_success.dart is excluded by !**/lib/src/protocol/**
  • modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_client/lib/src/protocol/protocol.dart is excluded by !**/lib/src/protocol/**
  • modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/lib/src/generated/auth_success.dart is excluded by !**/generated/**
  • modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/lib/src/generated/protocol.dart is excluded by !**/generated/**
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_client/lib/src/protocol/client.dart is excluded by !**/lib/src/protocol/**
📒 Files selected for processing (8)
  • modules/new_serverpod_auth/serverpod_auth_email/serverpod_auth_email_server/lib/src/endpoints/email_account_endpoint.dart (4 hunks)
  • modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/lib/serverpod_auth_session_server.dart (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/lib/src/business/auth_sessions.dart (2 hunks)
  • modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/lib/src/models/auth_success.spy.yaml (1 hunks)
  • modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/test/integration/auth_sessions_authentication_handler_test.dart (4 hunks)
  • modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/test/integration/auth_sessions_destroy_test.dart (3 hunks)
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart (10 hunks)
  • tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart (13 hunks)
🔇 Additional comments (23)
modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/lib/src/models/auth_success.spy.yaml (1)

1-11: Well-designed model with clear documentation.

The AuthSuccess model effectively encapsulates authentication session information with appropriate field types. The documentation clearly explains the purpose of each field, particularly the helpful clarification that scopeNames represents session-specific scopes independent of the user's inherent permissions.

modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/lib/serverpod_auth_session_server.dart (1)

5-6: Export addition correctly implemented.

The AuthSuccess class is properly added to the public exports, making it available for use in other modules as intended.

modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/test/integration/auth_sessions_authentication_handler_test.dart (4)

57-63: Correct adaptation to new AuthSuccess return type.

The test correctly extracts the sessionKey from the returned AuthSuccess object, maintaining the same test behavior while adapting to the new API.


130-136: Consistent pattern implementation.

The refactoring pattern is consistently applied across all test setups, correctly handling the new return type.


168-175: Proper handling of AuthSuccess object.

The test correctly adapts to the new return type while preserving the original test logic.


229-236: Consistent refactoring implementation.

The same pattern is correctly applied, showing systematic and thorough adaptation to the new API.

modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/test/integration/auth_sessions_destroy_test.dart (3)

23-29: Systematic refactoring correctly applied.

The test properly adapts to the new AuthSuccess return type by extracting the sessionKey property, maintaining test functionality while accommodating the API change.


114-127: Consistent pattern for multiple session creation.

Both session key assignments correctly follow the new pattern, showing thorough adaptation to the updated API.


181-194: Proper handling maintained across all test scenarios.

The refactoring is consistently applied to all session creation instances in the test file.

tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/email_account_endpoint_test.dart (6)

115-124: Excellent variable naming and API adaptation.

The variable is appropriately renamed from sessionKey to authSuccess to reflect the actual return type, and the session key is correctly accessed via the .sessionKey property.


155-167: Consistent refactoring pattern applied.

The login test correctly follows the same pattern, demonstrating systematic adaptation across all authentication methods.


291-303: Proper adaptation for password reset functionality.

The password reset test correctly handles the new return type while maintaining the same verification logic.


366-378: Thorough coverage of authentication scenarios.

All authentication test scenarios are consistently updated to handle the new AuthSuccess return type.


439-450: Extension method properly updated.

The helper extension method correctly adapts to return the session key from the AuthSuccess object, maintaining backward compatibility for existing test code.


496-503: Helper method correctly refactored.

The password change helper method properly returns the session key from the AuthSuccess object, completing the systematic refactoring.

modules/new_serverpod_auth/serverpod_auth_session/serverpod_auth_session_server/lib/src/business/auth_sessions.dart (2)

141-141: Enhanced return type for better authentication context.

The method signature change from Future<String> to Future<AuthSuccess> aligns perfectly with the PR objective to provide more comprehensive authentication details upon login success.


179-186: Well-structured AuthSuccess object creation.

The implementation correctly constructs the AuthSuccess object with all required fields:

  • sessionKey: Built using the existing session key generation logic
  • authUserId: Passed from the method parameter
  • scopeNames: Derived from the scopes parameter and stored in the session

This provides clients with comprehensive authentication information while maintaining the existing session key functionality.

modules/new_serverpod_auth/serverpod_auth_email/serverpod_auth_email_server/lib/src/endpoints/email_account_endpoint.dart (2)

11-11: Documentation updated to reflect enhanced return type.

The comment correctly describes that the method now returns a session object rather than just a session key string.


14-14: Consistent return type updates across all authentication methods.

All authentication-related methods (login, finishRegistration, finishPasswordReset, and _createSession) have been consistently updated to return Future<AuthSuccess> instead of Future<String>. This maintains API consistency and provides clients with comprehensive authentication information.

Also applies to: 55-55, 119-119, 140-140

tests/serverpod_new_auth_test/serverpod_new_auth_test_server/test/integration/test_tools/serverpod_test_tools.dart (4)

17-22: Import aliases properly organized for new dependencies.

The import aliases have been correctly updated to accommodate the new AuthSuccess type from serverpod_auth_session_server and maintain proper aliasing for other dependencies.


142-142: Method signatures correctly updated for AuthSuccess return type.

All authentication method signatures in the test endpoints have been properly updated to return Future<_i4.AuthSuccess> with appropriate type casting, maintaining consistency with the updated endpoint implementations.

Also applies to: 167-167, 208-208, 233-233, 270-270, 297-297


210-210: Parameter types correctly use updated import aliases.

The UuidValue parameters now correctly reference _i5.UuidValue following the import alias reorganization.

Also applies to: 272-272


316-316: UserProfile endpoint signatures updated with correct import aliases.

All UserProfileEndpoint method signatures have been properly updated to use the correct import aliases (_i6.UserProfileModel, _i7.ByteData) following the reorganization.

Also applies to: 335-335, 343-343, 362-362, 370-370, 372-372, 391-391, 399-399, 420-420, 428-428, 449-449


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

tp added 2 commits June 25, 2025 07:36
To be returned from a successful login, instead of just the `String` `sessionKey`

This additionally contains the `authUserId` and `scopes`.

This will be used in the client "session manager" for `serverpod_auth_session`.
@tp
tp force-pushed the auth-session-auth-success branch from eddf5a1 to b02ea95 Compare June 25, 2025 05:37
@tp

tp commented Jun 25, 2025

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 25, 2025

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tp
tp marked this pull request as ready for review June 25, 2025 07:53
@tp
tp requested a review from exaby73 June 26, 2025 09:57

@exaby73 exaby73 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@tp
tp merged commit 6d27cfc into serverpod:main Jun 26, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 26, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants