Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push Notification for Multiple Users #51

Open
NwinNwin opened this issue Feb 28, 2024 · 0 comments · May be fixed by icssc/zotnfound-backend#9
Open

Push Notification for Multiple Users #51

NwinNwin opened this issue Feb 28, 2024 · 0 comments · May be fixed by icssc/zotnfound-backend#9
Assignees

Comments

@NwinNwin
Copy link
Member

Description

  • NOTE: Push Notification only works on deployed website
  • Push Notification functionality works BUT:
    • It can only send notification to 1 user
    • it's currently a backend route, we want to make it a function that send notification everytime there's a New Post
  • TO FIX: we need to store users' subscription key(will talk ab this more in section below) in DB to query and send notification to all users that subscribed.

Would recommend watching this Video before starting to look at the instruction below as it helps you understand some concept of Push Notif in Web

Access our current TEST push notification :

  • Go to zotnfound.com/playground:

    • For Code: go to components/Playground.jsx
  • Open your console in inspect

  • Click register for push notification

    • For Code: line 121 triggers function registerServiceWorker(line 25) to register serviceWorker (this allows push notif)
  • Click subscribe for push notif

    • For Code: line 126 triggers function subscribeUser(line 42) to ask client for push notif permission
    • This will ask you to allow notification
      • image
  • Once clicked subscribe, it will print out a json IN CONSOLE that looks like this {endpoint, p256dh, auth}

    • image
    • This is like a key or phone number that server can contact and send notification to.
      • For this task: WE WANT TO STORE THIS KEY IN DB to send them notification
  • Once you copied the key and save it in a safe place, Run our ZotNFound backend locally (on branch webpush-api)

  • Replace subscription value (Prev req.body) with that key (this will allow server to send notif to the subscribed browser key upon using the route)

  • Open Postman

  • Run POST localhost:3001/notification

  • you will receive a push notification (let me know if you got any problem)

To Do:

  • The problem right now is our webpush function can only send 1 to 1 subscribed users
  • Create a route to store the key in our database when users subscribe for notification
  • Create a push notification Function that take in an array of keys to send notifs to all of them
  • Modify POST /items so that it can retrieve an array of keys from db and use the push notification Function to send notifs

Resources:

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 a pull request may close this issue.

2 participants