Skip to content

feat(discord): implement auto-join for Discord guild and update scopes#64

Merged
mergify[bot] merged 2 commits intomainfrom
update-discord
Mar 19, 2026
Merged

feat(discord): implement auto-join for Discord guild and update scopes#64
mergify[bot] merged 2 commits intomainfrom
update-discord

Conversation

@Zaid-maker
Copy link
Owner

@Zaid-maker Zaid-maker commented Mar 19, 2026

Summary by CodeRabbit

  • New Features

    • Users are now automatically added to a configured Discord server after linking.
    • Settings page shows a "Re-authenticate" option alongside unlink, and displays join-failure warnings.
    • Discord authorization now requests guild-join permission.
  • Bug Fixes

    • Improved detection, reporting, and UI feedback for Discord join failures.
  • Chores

    • Persisted a Discord join-status for users (database migration and API support).

@vercel
Copy link

vercel bot commented Mar 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dev-meter-bypy Ready Ready Preview, Comment Mar 19, 2026 7:58pm
dev-meter-v2 Ready Ready Preview, Comment Mar 19, 2026 7:58pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Added Discord guild auto-join on OAuth callback, persisted per-user join status, expanded OAuth scope to request guilds.join, exposed API endpoints to read/update discordJoinStatus, and added a DB migration and UI updates to show join failures and allow re-authentication.

Changes

Cohort / File(s) Summary
Callback & Auto-Join
client/app/api/user/discord/callback/route.ts
Added addUserToDiscordGuild helper performing a PUT to Discord guild-members with a 5s timeout; callback persists Discord linkage, calls helper, and sets discordJoinStatus to "joined" or "failed" and redirects accordingly.
OAuth Connect
client/app/api/user/discord/connect/route.ts
Expanded OAuth scope from identify to identify guilds.join for auto-join capability.
Discord API & CRUD
client/app/api/user/discord/route.ts
Added DiscordJoinStatus type, included discordJoinStatus in GET responses, cleared it on DELETE, and added PATCH to validate and update discordJoinStatus for the authenticated user.
Settings UI
client/app/settings/page.tsx
Added "use i18n";, extended DiscordLinkStatus to include discordJoinStatus, handle linked_join_failed query (toast + PATCH to persist failure), show inline warning when join failed, and replace single unlink button with "Re-authenticate" + unlink buttons.
Database migration & schema
client/prisma/migrations/.../migration.sql, client/prisma/schema.prisma
Added discordJoinStatus TEXT/String? column to User model via migration and schema update.

Sequence Diagram(s)

sequenceDiagram
    participant Browser as Browser
    participant OAuth as Discord OAuth
    participant Callback as App Callback
    participant DB as Database (Prisma)
    participant DiscordAPI as Discord Guild API
    participant Settings as Settings Page

    Browser->>OAuth: Request auth (scope: identify guilds.join)
    OAuth->>Browser: Redirect with code
    Browser->>Callback: GET /callback?code=...
    Callback->>Callback: Exchange code for token
    Callback->>DB: Update user with Discord linkage
    Callback->>DiscordAPI: PUT /guilds/{guild.id}/members (user token) [5s timeout]
    alt Discord join succeeds
        DiscordAPI->>Callback: 201/204 OK
        Callback->>DB: Set discordJoinStatus = "joined"
        Callback->>Browser: Redirect -> linked
    else Discord join fails
        DiscordAPI->>Callback: Error / missing config
        Callback->>DB: Set discordJoinStatus = "failed"
        Callback->>Browser: Redirect -> linked_join_failed
        Browser->>Settings: PATCH /api/user/discord { joinStatus: "failed" } then revalidate
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through OAuth fields so wide,

I fetched a token, took the stride.
If guild doors open, I will cheer—
If they slam, I nudge you near.
Re-auth or unlink, hoppity-dear.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately captures the main changes: implementing auto-join functionality for Discord guild and updating OAuth scopes to include guilds.join.

✏️ 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 update-discord
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
client/app/settings/page.tsx (1)

90-94: Persist guild-join outcome if this warning should remain visible after refresh.

Lines 90-94 show a warning and call mutate("/api/user/discord"), but client/app/api/user/discord/route.ts (Lines 15-30) only returns link metadata, not guild-join status. The warning becomes non-representable after navigation/reload. Consider storing and returning a durable join-state field.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/app/settings/page.tsx` around lines 90 - 94, The warning for
"linked_join_failed" is ephemeral because mutate("/api/user/discord") only
returns link metadata; persist a durable join-state (e.g., joinStatus) on the
user record and surface it from the GET handler in
client/app/api/user/discord/route.ts so UI can represent the outcome after
reload; when you detect status === "linked_join_failed" in the settings page,
call an API mutation (or PATCH/POST endpoint) to set joinStatus = "failed" for
that user and then call mutate("/api/user/discord") so the returned payload
includes the new joinStatus and the warning can be re-rendered consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@client/app/api/user/discord/callback/route.ts`:
- Around line 25-55: The addUserToDiscordGuild function currently performs fetch
without timeout or local error handling; update it to create an AbortController,
set a timeout (e.g., 5s) that calls controller.abort(), pass controller.signal
into fetch, and wrap the fetch/response handling in a try-catch so any thrown
error or abort is caught locally; on error or non-OK/non-201/204 responses
return false (and log the error with details) so the caller can set
linked_join_failed rather than letting the exception bubble as internal_error;
also clear the timeout timer on success or failure to avoid leaks.

---

Nitpick comments:
In `@client/app/settings/page.tsx`:
- Around line 90-94: The warning for "linked_join_failed" is ephemeral because
mutate("/api/user/discord") only returns link metadata; persist a durable
join-state (e.g., joinStatus) on the user record and surface it from the GET
handler in client/app/api/user/discord/route.ts so UI can represent the outcome
after reload; when you detect status === "linked_join_failed" in the settings
page, call an API mutation (or PATCH/POST endpoint) to set joinStatus = "failed"
for that user and then call mutate("/api/user/discord") so the returned payload
includes the new joinStatus and the warning can be re-rendered consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d56d7345-4fca-4e69-a1c9-596a37313d89

📥 Commits

Reviewing files that changed from the base of the PR and between 176a0b0 and 8d5148a.

📒 Files selected for processing (3)
  • client/app/api/user/discord/callback/route.ts
  • client/app/api/user/discord/connect/route.ts
  • client/app/settings/page.tsx

@Zaid-maker
Copy link
Owner Author

@mergify queue

@mergify
Copy link
Contributor

mergify bot commented Mar 19, 2026

Merge Queue Status

  • Entered queue2026-03-19 20:00 UTC · Rule: default
  • Checks skipped · PR is already up-to-date
  • Merged2026-03-19 20:00 UTC · at bffde81e159715501e1625bd0b2c6e80b30f30f3

This pull request spent 6 seconds in the queue, with no time running CI.

Required conditions to merge
  • any of [🛡 GitHub branch protection]:
    • check-success = Vercel – dev-meter-bypy
    • check-neutral = Vercel – dev-meter-bypy
    • check-skipped = Vercel – dev-meter-bypy
  • any of [🛡 GitHub branch protection]:
    • check-success = Vercel Preview Comments
    • check-neutral = Vercel Preview Comments
    • check-skipped = Vercel Preview Comments
  • any of [🛡 GitHub branch protection]:
    • check-success = Vercel – dev-meter-v2
    • check-neutral = Vercel – dev-meter-v2
    • check-skipped = Vercel – dev-meter-v2
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Mergify Merge Protections
    • check-skipped = Mergify Merge Protections
    • check-success = Mergify Merge Protections

@mergify mergify bot added the queued label Mar 19, 2026
@mergify mergify bot merged commit 7a3540b into main Mar 19, 2026
6 of 7 checks passed
@mergify mergify bot removed the queued label Mar 19, 2026
@Zaid-maker Zaid-maker deleted the update-discord branch March 19, 2026 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant