Skip to content

Fix discord login issue#1028

Merged
evanpelle merged 2 commits intomainfrom
login
Jun 4, 2025
Merged

Fix discord login issue#1028
evanpelle merged 2 commits intomainfrom
login

Conversation

@scottanderson
Copy link
Contributor

Fixes #1016

Description:

Fix the zod user schema validation to make roles optional. This was causing a validation error when looking up the user's roles.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced
  • I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

Walkthrough

The changes update error formatting for schema validation in JWT handling, adjust the roles property in user-related schemas and types from required to optional, and ensure the roles field can be undefined throughout the server and client code. No control flow or exported API signatures are otherwise changed.

Changes

Files/Groups Change Summary
src/client/jwt.ts Switched error logging to use z.prettifyError for schema validation failures.
src/core/ApiSchemas.ts Made player.roles in UserMeResponseSchema optional instead of required.
src/server/Client.ts Changed roles constructor parameter type from string[] | null to string[] | undefined.
src/server/Worker.ts Updated roles variable to be string[] | undefined and assigned from validated user claims.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Server
    participant JWTValidator as JWT Validator
    participant Schema as Schema Validator

    Client->>Server: Join game with token
    Server->>JWTValidator: Validate token
    JWTValidator-->>Server: Token claims
    Server->>Schema: Validate user schema (roles optional)
    Schema-->>Server: Validation result
    Server->>Client: Proceed to join game (roles may be undefined)
Loading

Assessment against linked issues

Objective Addressed Explanation
Notify player if not in Discord server and prevent joining game (#1016) The changes only make roles optional and update error formatting; no notification or block.
Token should not be saved or should be deleted if user not in Discord server (#1016) No logic added to prevent saving/deleting token based on Discord server membership.

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Improved error formatting using z.prettifyError (src/client/jwt.ts) This change is unrelated to Discord membership or join logic as described in the linked issue.

Possibly related PRs

Suggested labels

Bug Fix

Suggested reviewers

  • evanpelle

Poem

In the code, a gentle breeze,
Roles now may come or leave with ease.
Errors dressed in prettier ways,
Await the user's login phase.
Though Discord checks are still to come,
The groundwork's set—onward, devs, drum!

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-04T02_10_31_652Z-debug-0.log


📜 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 270244c and acdf101.

📒 Files selected for processing (4)
  • src/client/jwt.ts (4 hunks)
  • src/core/ApiSchemas.ts (1 hunks)
  • src/server/Client.ts (1 hunks)
  • src/server/Worker.ts (2 hunks)
🔇 Additional comments (8)
src/server/Client.ts (1)

15-15: Good type alignment with optional roles schema.

The change from string[] | null to string[] | undefined is correct and follows TypeScript conventions for optional values. This properly aligns with the schema changes making roles optional.

src/core/ApiSchemas.ts (1)

45-45: Core fix for Discord login validation issue.

Making the roles field optional correctly addresses the validation failure when Discord login doesn't return user roles. This targeted change allows the schema to handle both scenarios gracefully.

src/client/jwt.ts (4)

2-2: Good addition for better error formatting.

Adding the zod import enables the use of z.prettifyError for cleaner validation error messages throughout the file.


142-144: Improved error debugging for token validation.

Using z.prettifyError instead of raw JSON stringification provides much clearer error messages when JWT token validation fails. This will help diagnose similar schema validation issues in the future.


172-173: Consistent error formatting for refresh response.

The same error formatting improvement applied to refresh token validation maintains consistency and improves debugging experience.


199-200: Enhanced getUserMe error messages.

Using z.prettifyError for user data validation errors will provide clearer feedback when issues occur with roles or other user fields.

src/server/Worker.ts (2)

317-317: Correct variable declaration for optional roles.

Changing from const roles: string[] | null = null to let roles: string[] | undefined properly supports the optional roles field and aligns with the schema changes.


326-326: Proper assignment of optional roles data.

The assignment roles = result.player.roles correctly handles the case where user roles are available from the getUserMe response, while maintaining undefined as the default when roles aren't present.


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

Copy link
Collaborator

@evanpelle evanpelle left a comment

Choose a reason for hiding this comment

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

Thanks!

@github-project-automation github-project-automation bot moved this from Triage to Final Review in OpenFront Release Management Jun 4, 2025
@evanpelle evanpelle merged commit a02037a into main Jun 4, 2025
11 checks passed
@evanpelle evanpelle deleted the login branch June 4, 2025 02:33
@github-project-automation github-project-automation bot moved this from Final Review to Complete in OpenFront Release Management Jun 4, 2025
evanpelle pushed a commit that referenced this pull request Jun 4, 2025
Fixes #1016

## Description:

Fix the zod user schema validation to make roles optional. This was
causing a validation error when looking up the user's roles.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
1brucben pushed a commit that referenced this pull request Jun 5, 2025
Fixes #1016

## Description:

Fix the zod user schema validation to make roles optional. This was
causing a validation error when looking up the user's roles.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
@scottanderson scottanderson self-assigned this Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Complete

Development

Successfully merging this pull request may close these issues.

Can't join game when using Discord login if not in the Discord server

2 participants