feat: implement real-time dashboard sync via Pusher - #696
Conversation
|
@Dev1822 is attempting to deploy a commit to the vishnukothakapu's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
Next review available in: 41 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
📝 WalkthroughWalkthroughUser registration now creates a workspace and owner membership. Link and profile APIs use workspace context. The dashboard adds webhook configuration, and click events can trigger signed webhooks. Pusher server, client, and private-channel authentication support are added. ChangesWorkspace scoping
Webhook configuration and delivery
Pusher authentication infrastructure
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant LinkClickClient
participant ClickRoute
participant WebhookEndpoint
LinkClickClient->>ClickRoute: Record link click
ClickRoute->>ClickRoute: Create HMAC-SHA256 signature
ClickRoute->>WebhookEndpoint: Send signed JSON POST
WebhookEndpoint-->>ClickRoute: Return response or failure
ClickRoute-->>LinkClickClient: Return click response
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 8
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/api/auth/register/route.ts`:
- Around line 49-73: Add Workspace and WorkspaceMember models, their user/link
relations, and Link.workspaceId to prisma/schema.prisma so the registration
transaction and workspace-scoped link queries work. Add a migration that creates
the workspace and membership tables, creates a workspace and OWNER membership
for every existing user, assigns each user’s links to that workspace, and copies
the existing layout, SEO, and theme values into the workspace records. Update
app/api/auth/register/route.ts, app/api/links/route.ts,
app/api/user/layout/route.ts, app/api/user/seo/route.ts, and
app/api/user/theme/route.ts as needed to use the new schema consistently.
In `@app/api/links/click/route.ts`:
- Around line 70-78: Update the webhook dispatch in the click route to run
through the supported after() background mechanism instead of an unawaited fetch
before returning. Await the POST request within the after() callback, add a
short request timeout, and retain the existing payload, headers, and error
logging.
In `@app/api/pusher/auth/route.ts`:
- Around line 14-24: Update the parameter parsing in the Pusher auth route to
use URLSearchParams, retrieving values by the socket_id and channel_name keys
with URL decoding handled automatically. Validate both values before the
private-channel authorization check and return a 400 Bad Request response when
either is missing; preserve the existing session ownership check and
authorization flow for valid requests.
In `@app/api/settings/route.ts`:
- Around line 24-35: Restrict webhook destinations in app/api/settings/route.ts
lines 24-35 by validating and normalizing the URL before assigning
updateData.webhookUrl: require a valid URL with an HTTPS scheme, resolve its
hostname, and reject loopback, private, link-local, metadata, and other reserved
addresses. In app/api/links/click/route.ts lines 71-78, apply the same egress
validation immediately before dispatch and configure the request to reject
redirects.
- Around line 16-34: Fix the ESLint issues in the settings update handler by
declaring updateData as const with an explicit appropriate type, and replace the
inline require('crypto') call with a module-scope randomBytes import. Keep the
existing webhookSecret generation behavior in the webhookUrl update path
unchanged.
In `@lib/pusher.ts`:
- Around line 1-2: Add pusher and pusher-js to the project's dependencies, then
regenerate package-lock.json so both packages and their resolved dependency
metadata are recorded. Keep the existing imports in lib/pusher.ts unchanged.
In `@lib/workspace.ts`:
- Around line 4-24: Update getActiveWorkspace in lib/workspace.ts so a supplied
workspace ID that lacks membership returns null instead of falling back to the
earliest workspace; use the default workspace only when no ID was supplied. In
app/api/links/route.ts lines 51-57 and 303-307, app/api/links/reorder/route.ts
lines 26-29, app/api/user/layout/route.ts lines 27-28, app/api/user/seo/route.ts
lines 36-37, and app/api/user/theme/route.ts lines 24-25, preserve the existing
failure behavior when the workspace lookup returns null and prevent reads or
updates against the default workspace.
In `@prisma/schema.prisma`:
- Around line 65-66: Add and deploy a Prisma migration for the `webhookUrl` and
`webhookSecret` fields in the relevant model, ensuring existing databases
receive both nullable columns queried by the routes. Keep the schema and
generated migration aligned.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 54de3406-2bf4-4b33-a541-4dc76ba1bfb9
📒 Files selected for processing (15)
app/api/auth/register/route.tsapp/api/links/click/route.tsapp/api/links/reorder/route.tsapp/api/links/route.tsapp/api/pusher/auth/route.tsapp/api/settings/route.tsapp/api/user/layout/route.tsapp/api/user/seo/route.tsapp/api/user/theme/route.tsapp/dashboard/DashboardClient.tsxapp/dashboard/WebhookSection.tsxapp/dashboard/page.tsxlib/pusher.tslib/workspace.tsprisma/schema.prisma
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
pls resolve the merge conflicts @Dev1822 |
|
also, the Vercel build is failing on It’s the same Prisma issue as before — Could you take a look at the migration/backfill for the existing rows? Using |
69199b5 to
8518840
Compare
|
@Dev1822 , the Vercel build is still failing on The only errors now are that Looks like the two packages are missing from the branch’s dependencies. Could you check |
b4fff2d to
b868ece
Compare
b868ece to
eb021b3
Compare
Description
Integrates Pusher WebSockets to enable real-time synchronization across the LinkID dashboard. When a user updates, deletes, or adds their links on one device (e.g., their mobile phone), the dashboard UI automatically and seamlessly updates on all other active devices without requiring a manual page refresh.
Closes #692
Changes Made
pusherandpusher-js.lib/pusher.tsinstance to handle Pusher events./api/pusher/authto authenticate NextAuth sessions and ensure users can only subscribe to their own private channels (private-user-[userId]).links/route.ts,links/[id]/route.ts, andlinks/reorder/route.ts) to broadcast alinks-updatedevent to the user's private channel whenever links are mutated.DashboardClient.tsxto instantiate the Pusher client and subscribe to the user's private channel.useEffecthook that triggersrouter.refresh()upon receiving alinks-updatedevent, seamlessly fetching the latest state from the server.Setup Instructions for Reviewers
To test this locally, you will need to create a free Pusher account, create an App channels instance, and add the following keys to your
.env:Verification
Summary by CodeRabbit