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

Migrated notifications to Firebase #37

Closed
wants to merge 4 commits into from
Closed

Migrated notifications to Firebase #37

wants to merge 4 commits into from

Conversation

eswarasai
Copy link

Fixes: #23

Changes:

  • Removed Pusher Beams integration
  • Setup Firebase Admin SDK for subscribing devices to topics and sending push notifications on proposal events
  • Added new table for storing device tokens

How to test and review this PR?

.gitignore Outdated
@@ -4,6 +4,8 @@ dist
build
.env

# Firebase service account
firebase.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make it so we don't need firebase.json file but instead rely on .env file?

@@ -0,0 +1 @@
v16.17.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to force v16 here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to keep dev env consistent across the repos. Updated the same for Snapshot UI repo as well.

const messaging = getMessaging(firebaseApp);
const hubURL = process.env.HUB_URL || 'https://hub.snapshot.org';

const getUserSpaces = async user => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use this format for all the functions and add types to it?

Suggested change
const getUserSpaces = async user => {
async function getUserSpaces(user: string) {

credential: cert({
projectId: FIREBASE_PROJECT_ID,
clientEmail: FIREBASE_CLIENT_EMAIL,
privateKey: FIREBASE_PRIVATE_KEY
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change the env var wont work because it include new lines

Suggested change
privateKey: FIREBASE_PRIVATE_KEY
privateKey: (FIREBASE_PRIVATE_KEY || '').replace(/\\n/g, '\n')

src/api.ts Outdated
}
});

router.post('/subscription', async (req, res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This route assume the user join / leave a space using snapshot.org but he may activate notification on snapshot.org but actually join or leave from another integration that wont trigger this route. Also this has no authentication anyone could exploit this route and subscribe any user to a specific space. We should instead use the code that replay the messages from the hub to check when there is a new follow or unfollow action. Similar than what we do to populate proposal events.

@eswarasai eswarasai closed this by deleting the head repository Sep 11, 2023
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.

Make browser notifications works for all space
3 participants