• Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An example repo for using browser push notifications with Vue.js and Firebase

Vue.js Push Notification Example

An example repo for using browser push notifications with Vue.js. We also use Firebase in this example as it can be used to send the notifications for free and with zero-configuration.

Frontend

Signing up in the form

signup demo

Showing a notification

notification demo

Requirements

  • Firebase account
  • Server running on the project root

Installation

  • Create a manifest.json following this structure
  • Create a firebase.json with the Firebase Web credentials
  • Make sure the Firebase table can be written to

Sending Notifications

Using Firebase Function

Be sure to change into the firebase-function/functions/ directory and run npm install.

Initial Setup

Copy the "Server key" from Project Settings > Cloud Messaging page. Store it as follows in a file named firebase-function/functions/google-push-key.json:

{
  "key": "THAT SERVER KEY FROM CLOUD MESSAGING"
}

Running the app locally

In order to get the app to work locally, Firebase needs to be authenticated using a JSON file with the correct application keys and secrets.

Download the Firebase Admin SDK file from the Project Settings > Service Accounts page. Rename it and place it in firebase-function/firebase-adminsdk.json. If no Firebase auth file is found, the app will not be able to run locally. You don't need the auth file when running in the Firebase cloud function environment.

You can run the app locally by just changing to the firebase-function/functions/ folder and using npm run start.

Deploy

Read the Firebase Functions docs on getting started.

Single User

You can send the notification using cURL:

curl --header "Authorization: key=<YOUR_FIREBASE_SERVER_KEY>" --header
"Content-Type: application/json" https://android.googleapis.com/gcm/send -d
"{\"registration_ids\":[\"<SUBSCRIBER_ID>\"]}"

To get a <SUBSCRIBER_ID> for your user, you can pull it out of the endpoint that is saved to the Firebase database when the user is stored.

For example your endpoint may look like this: "https://android.googleapis.com/gcm/send/<SUBSCRIBER_ID>" and you can take that crazy ID out and place it in the registration_ids array.

More Repositories

1

audio-to-svg-waveform

Convert an audio file to a compressed (gzip) SVG waveform
JavaScript
22
star
2

harvey-serverless

Harvey brings Harvest time tracking into Slack to get your team quickly and easily tracking their hours and keep your projects running smoothly.
TypeScript
9
star
3

valet-WordPress-subdirectory

Use Valet with WordPress in a subdirectory
PHP
9
star
4

wordpress-starter

A submodule installation of WordPress including the WordPress testing suite, linting, formatting, autoloading, Docker, and wp-cli
PHP
7
star
5

vue-radio-checkbox

A set of custom radio and checkbox components for Vue.js
JavaScript
6
star
6

kafka-docker-node

Run a containerized Kafka server and interact with it using Node.js
JavaScript
5
star
7

ansible-amazon-node

Ansible scripts that setup Node.js for Amazon Linux AMIs
5
star
8

haproxy-ansible

A simple haproxy 1.5 ansible playbook example with ssl termination
5
star
9

harvey

Harvey is a Slack bot that can report the hours from Harvest for your team on a weekly or monthly basis
JavaScript
4
star
10

ansible-letsencrypt-nginx

Ansible script that installs letsencrypt and adds a domain
3
star
11

owly-api-php

A PHP Class to interface with the Owly API to generate short trackable URLs
PHP
3
star
12

Ansible-PHP-Settler

Ansible role that builds a PHP environment
HTML
2
star
13

vue-multi-dropdown

A custom dropdown component for Vue.js
CSS
2
star
14

code-quality

Reduce your cognitive overhead by installing these tools to format, lint, and test your code
2
star
15

vue-suggest

An inline typeahead component for Vue.js
JavaScript
1
star
16

Invoke-CLI

Invoke CLI tools.
PHP
1
star
17

browser

A small class to detect the browser and the operating system
PHP
1
star