Skip to content

feat: Real-time Notifications — Database Schema & API#38

Merged
Suharshit merged 4 commits into
developfrom
feat/real-time-notifications-6365568009124595657
Mar 11, 2026
Merged

feat: Real-time Notifications — Database Schema & API#38
Suharshit merged 4 commits into
developfrom
feat/real-time-notifications-6365568009124595657

Conversation

@Suharshit

Copy link
Copy Markdown
Owner

This PR implements a real-time notifications system for Vibely.

Key features:

  1. Database schema: Added a new migration (009_notifications.sql) that creates a notifications table with appropriate columns, constraints, an index for performance, and Row Level Security (RLS) policies allowing users to SELECT and UPDATE their own notifications.
  2. API routes:
    • GET /api/notifications: Returns paginated unread notifications for the authenticated user and an unread_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.
  3. Notification helper: Introduced a createNotification utility in lib/notify.ts to easily trigger new notifications using the Supabase admin client.
  4. Photo upload integration: Updated the POST /api/photos/[id]/complete route to call the createNotification helper, notifying the event host whenever a new photo is successfully uploaded.
  5. Types: Generated and updated the corresponding TypeScript interfaces in 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

- 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>
@vercel

vercel Bot commented Mar 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
vibely-web Ready Ready Preview, Comment Mar 11, 2026 1:29pm

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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

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.notifications table + notification_type enum 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.

Comment thread supabase/migrations/009_notifications.sql Outdated
Comment thread apps/vibely-web/lib/notify.ts Outdated
Comment thread apps/vibely-web/lib/notify.ts
Comment thread apps/vibely-web/app/api/notifications/route.ts
Comment thread apps/vibely-web/app/api/notifications/[id]/route.ts
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>
@Suharshit

Copy link
Copy Markdown
Owner Author

Update supabase/migrations/009_notifications.sql

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.

@google-labs-jules

Copy link
Copy Markdown
Contributor

Update supabase/migrations/009_notifications.sql

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.

Added WITH CHECK (auth.uid() = user_id) to the UPDATE policy to prevent users from reassigning their notifications.

- 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>
@Suharshit

Copy link
Copy Markdown
Owner Author

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).
- type: 'photo_uploaded' | 'member_joined' | 'event_expiring',
+ type: "photo_uploaded" | "member_joined" | "event_expiring",

update apps/vibely-web/lib/notify.ts, apps/vibely-web/app/api/notifications/[id]/route.ts, apps/vibely-web/app/api/notifications/route.ts

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

@google-labs-jules

Copy link
Copy Markdown
Contributor

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).
- type: 'photo_uploaded' | 'member_joined' | 'event_expiring',
+ type: "photo_uploaded" | "member_joined" | "event_expiring",

update apps/vibely-web/lib/notify.ts, apps/vibely-web/app/api/notifications/[id]/route.ts, apps/vibely-web/app/api/notifications/route.ts

Most 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 notify.ts, api/notifications/route.ts, and api/notifications/[id]/route.ts as requested.

- 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>
@Suharshit Suharshit merged commit 725fa5a into develop Mar 11, 2026
5 checks passed
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.

2 participants