Skip to content

Comments

Feat: Add Push Notification Service#127

Open
Emmzyemms wants to merge 2 commits intoDogStark:mainfrom
Emmzyemms:Push
Open

Feat: Add Push Notification Service#127
Emmzyemms wants to merge 2 commits intoDogStark:mainfrom
Emmzyemms:Push

Conversation

@Emmzyemms
Copy link

PR TEMPLATE

Description

Added Push Notification Service

Related Issues

Closed: #81
Please, there is a bug when running the backend
Screenshot 2026-02-21 224615

Changes Made - [ ]

 *Notification added

How to Test

  To test the Push Notification Service,

Backend Setup (backend/.env)
Add the credentials from your Service Account JSON:
env

Firebase Admin Credentials

FIREBASE_PROJECT_ID="your-project-id"
FIREBASE_CLIENT_EMAIL="your-service-account-email"
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"

Redis (Required for BullMQ Scheduling)

REDIS_HOST="localhost"
REDIS_PORT=6379

Frontend Setup (.env.local)
Add the Firebase Web Config:
env
NEXT_PUBLIC_FIREBASE_API_KEY="your-api-key"
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN="your-app.firebaseapp.com"
NEXT_PUBLIC_FIREBASE_PROJECT_ID="your-project-id"
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET="your-app.appspot.com"
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID="your-sender-id"
NEXT_PUBLIC_FIREBASE_APP_ID="your-app-id"
NEXT_PUBLIC_FIREBASE_VAPID_KEY="your-vapid-key"

  1. Test Step: Device Token Registration
    Start Services: Ensure Redis is running, then start your backend (npm run start:dev) and frontend (npm run dev).
    Login: Open the app in your browser and log in.
    Enable Notifications:
    Navigate to Settings (or /preferences).
    Toggle Push Notifications to "On".
    Verify Registration:
    The browser will prompt for notification permission. Click Allow.
    Check the browser's Network tab. You should see a successful POST request to /api/notifications/{userId}/device-tokens.
    Check your database device_tokens table to see the new entry for your user.
  2. Test Step: Sending a Notification
    You can trigger a notification by hitting the backend API. For testing, you can use a tool like Postman or curl.

Immediate Notification
bash
curl -X POST http://localhost:3000/api/notifications
-H "Content-Type: application/json"
-d '{
"userId": "your-user-uuid",
"title": "New Healthy Tip!",
"message": "Check out our new guide on pet nutrition.",
"category": "SYSTEM",
"metadata": {
"imageUrl": "https://example.com/pet-image.jpg"
}
}'
Scheduled Notification (Delayed)
To test the scheduling/BullMQ logic, add a scheduledFor date (ISO string):

bash
curl -X POST http://localhost:3000/api/notifications
-H "Content-Type: application/json"
-d '{
"userId": "your-user-uuid",
"title": "Reminder",
"message": "Scheduled checkup in 2 minutes.",
"category": "APPOINTMENT",
"scheduledFor": "2026-02-21T21:40:00.000Z"
}'
4. Verification
Foreground: If the app is open, you should see a browser notification (and a console log if you check developer tools).
Background: Close the app tab. Send the curl request. You should see a system-level push notification appear (handled by

firebase-messaging-sw.js
).
History: Go to the Notifications page (/notifications) in the app. The new notification should appear with its icon, rich description, and action button.
Action: Click "View Details" on a notification in the history list; it should redirect you to the actionUrl if provided.

Screenshots (if applicable)

Checklist

  • [ x] My code follows the project's coding style.
  • [ x] I have tested these changes locally.
  • [x ] Documentation has been updated where necessary.

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.

Push Notification Service

1 participant