Lovablefeatureadvanced

Add Real-Time Notifications to Lovable App

Add real-time notifications using Supabase Realtime with bell icon, toast alerts, and notification center.

What you'll get

A real-time notification system with bell icon, toast alerts, notification center, and Supabase Realtime integration.

The Prompt

Add real-time notifications to my Lovable app using Supabase Realtime.

REQUIREMENTS:
1. Create a "notifications" table and subscribe to INSERT events using Supabase Realtime.
2. Add a bell icon in the navbar with an unread count badge (red circle with number).
3. When a new notification arrives in real-time, show a toast alert in the bottom-right corner with the notification message and an action button.
4. Clicking the bell opens a notification dropdown/panel showing recent notifications, grouped by date (Today, Yesterday, Earlier).
5. Each notification has: icon (by type), title, message, timestamp (relative: "2 min ago"), read/unread state, and an optional action link.
6. Support notification types: info, success, warning, error — each with a different icon and color.
7. Add "Mark all as read" and "Clear all" actions in the notification panel.
8. Play a subtle notification sound on new notifications (with a mute option).

DATABASE:
- "notifications" table: id, user_id, type (info/success/warning/error), title, message, action_url, is_read, created_at
- RLS: Users can only read their own notifications.
- Index on (user_id, is_read, created_at) for fast queries.

SECURITY:
- Only send notifications to the intended user via RLS.
- Rate limit notification creation to prevent spam.
- Sanitize notification message content.

Replace these variables

VariableReplace with
[NOTIFICATION_TRIGGERS]Events that create notifications (e.g., new message, order update, form submission)

Tips for best results

Enable Realtime on the notifications table in Supabase Dashboard under Database > Replication.

Batch mark-as-read operations to reduce database calls when opening the notification panel.

Use a notification sound sparingly — users will mute or leave your app if it's annoying.

Follow-up prompts

Add push notifications

Add browser push notifications using the Web Push API so users receive alerts even when they're not on the site.

Add notification preferences

Add a notification settings page where users can choose which notification types they receive (in-app, email, push) per category.

Related prompts