feat: Real-time Notifications — Database Schema & API#38
Conversation
- Add migration `009_notifications.sql` with `notifications` table, RLS and index - Add `GET /api/notifications` for fetching unread notifications - Add `PATCH /api/notifications` and `PATCH /api/notifications/[id]` to mark as read - Add `createNotification` helper in `lib/notify.ts` - Update `POST /api/photos/[id]/complete` to notify event host on photo upload - Update `packages/shared/types/database.types.ts` with new table type Co-authored-by: Suharshit <125254345+Suharshit@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
Adds a basic notifications system backed by Supabase (schema + RLS), along with server utilities and API endpoints to fetch and mark notifications as read, and hooks notification creation into the photo upload completion flow.
Changes:
- Introduces
public.notificationstable +notification_typeenum with RLS and indexing. - Updates shared Supabase Database TypeScript types to include
notifications. - Adds notification creation helper + Next.js API routes for listing unread notifications and marking them read; creates a notification when a photo upload is completed.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| supabase/migrations/009_notifications.sql | Creates notifications table, enum type, index, and RLS policies. |
| packages/shared/types/database.types.ts | Adds notifications table typing for Supabase clients. |
| apps/vibely-web/lib/notify.ts | Adds server-side helper to insert notifications using the admin Supabase client. |
| apps/vibely-web/app/api/photos/[id]/complete/route.ts | Creates a host notification when a photo transitions to active. |
| apps/vibely-web/app/api/notifications/route.ts | Adds GET (fetch unread + count) and PATCH (mark read) endpoints. |
| apps/vibely-web/app/api/notifications/[id]/route.ts | Adds PATCH endpoint to mark a single notification as read. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The UPDATE RLS policy only has a USING clause. As written, a user who can update their own notification row can also change user_id (and other columns) to values they don’t own, effectively reassigning notifications to other users. Add a WITH CHECK (auth.uid() = user_id) clause (typically matching the USING condition) to prevent updating rows into a state the user shouldn’t be allowed to write. Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Update supabase/migrations/009_notifications.sqlThe UPDATE RLS policy only has a USING clause. As written, a user who can update their own notification row can also change user_id (and other columns) to values they don’t own, effectively reassigning notifications to other users. Add a WITH CHECK (auth.uid() = user_id) clause (typically matching the USING condition) to prevent updating rows into a state the user shouldn’t be allowed to write. |
Added |
- Added `WITH CHECK (auth.uid() = user_id)` to the UPDATE policy in `009_notifications.sql` to ensure users cannot reassign notifications. Co-authored-by: Suharshit <125254345+Suharshit@users.noreply.github.com>
update apps/vibely-web/lib/notify.ts,This file uses single quotes for the string-literal union type, but the rest of the repo generally uses double quotes (and Prettier defaults will rewrite these). Reformat to match existing style (e.g. apps/vibely-web/hooks/useEvents.ts uses double-quoted string literal unions). update apps/vibely-web/lib/notify.ts, apps/vibely-web/app/api/notifications/[id]/route.ts, apps/vibely-web/app/api/notifications/route.tsMost files in apps/vibely-web/lib/** start with a short header comment block explaining purpose/usage and most existing API route handlers include a header comment block documenting the endpoint and its behavior. |
Done. Changed the single quotes to double quotes for the type parameter to match the project's Prettier style, and added documentation header blocks to |
- Change single quotes to double quotes for the type parameter in `apps/vibely-web/lib/notify.ts`. - Add documentation headers explaining the files' purposes in `apps/vibely-web/lib/notify.ts`, `apps/vibely-web/app/api/notifications/route.ts`, and `apps/vibely-web/app/api/notifications/[id]/route.ts`. Co-authored-by: Suharshit <125254345+Suharshit@users.noreply.github.com>
This PR implements a real-time notifications system for Vibely.
Key features:
009_notifications.sql) that creates anotificationstable with appropriate columns, constraints, an index for performance, and Row Level Security (RLS) policies allowing users toSELECTandUPDATEtheir own notifications.GET /api/notifications: Returns paginated unread notifications for the authenticated user and anunread_count.PATCH /api/notifications: Allows marking multiple notifications (or all of them) as read.PATCH /api/notifications/[id]: Allows marking a specific notification as read.createNotificationutility inlib/notify.tsto easily trigger new notifications using the Supabase admin client.POST /api/photos/[id]/completeroute to call thecreateNotificationhelper, notifying the event host whenever a new photo is successfully uploaded.packages/shared/types/database.types.ts.All validations pass and the code is ready for review.
PR created automatically by Jules for task 6365568009124595657 started by @Suharshit