How to use the firebase.messaging function in firebase

To help you get started, we’ve selected a few firebase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tarex / react-firebase-tvshow-tracking / src / helper / firebase / index.js View on Github external
import firebase from 'firebase';
import ReduxSagaFirebase from 'redux-saga-firebase';
import config from '../../config';

const FirebaseApp = firebase.initializeApp(config.firebase);

export const RSF = new ReduxSagaFirebase(FirebaseApp);

export const FirebaseDB = firebase.database();
// firebase.database.enableLogging(false, false);
export const FirebaseAuth = firebase.auth();

export const FirebaseMsg = firebase.messaging();

export const getFirebaseAuthProvider = provider => {
  switch (provider) {
    case 'facebook':
      return new firebase.auth.FacebookAuthProvider();
    case 'google':
      return new firebase.auth.GoogleAuthProvider();
    case 'github':
      return new firebase.auth.GithubAuthProvider();
    case 'twitter':
      return new firebase.auth.TwitterAuthProvider();
    default:
      return null;
  }
};
github Leocardoso94 / push-notification-demo / src / push-notification.js View on Github external
export const askForPermissioToReceiveNotifications = async () => {
  try {

    const messaging = firebase.messaging();

    await messaging.requestPermission();
    const token = await messaging.getToken();
    console.log('user token: ', token);

    return token;
  } catch (error) {
    console.error(error);
  }
}
github Temzasse / yak-chat / client / src / services / notifications.js View on Github external
import * as firebase from 'firebase';

firebase.initializeApp({
  apiKey: 'AIzaSyCBI49-UdKW6iyayFhOnGnq4gBthx-2xe8',
  authDomain: 'yak-chat-779ce.firebaseapp.com',
  databaseURL: 'https://yak-chat-779ce.firebaseio.com',
  projectId: 'yak-chat-779ce',
  storageBucket: 'yak-chat-779ce.appspot.com',
  messagingSenderId: '812078557420'
});

const messaging = firebase.messaging();

export async function getNotificationToken() {
  try {
    const token = await messaging.getToken();
    return token;
  } catch (e) {
    console.log('Failed to get token...', e);
  }
  return null;
}

const initNotifications = () => {
  messaging.requestPermission()
    .then(() => {
      console.log('> Notification permission granted.');
github n6g7 / redux-saga-firebase / example / src / redux / sagas / messaging.js View on Github external
function* requestPermissionSaga() {
  const messaging = firebase.messaging()

  try {
    yield messaging.requestPermission()
    const token = yield messaging.getToken()
    yield put(setRegistrationToken(token))
  } catch (error) {
    console.warn('Notifications blocked')
  }
}
github collardeau / firebase-ignite / src / config.js View on Github external
const prodConfig = {
  apiKey: '',
  authDomain: '',
  databaseURL: '',
  storageBucket: '',
  messagingSenderId: ''
};

const isProd = process.env.NODE_ENV === 'production';
const firebaseConfig = isProd ? prodConfig : stagingConfig;

firebase.initializeApp(firebaseConfig);
export const ref = firebase.database().ref();
export const firebaseAuth = firebase.auth;
export const storage = firebase.storage();
export const messaging = firebase.messaging();
github cribbl / miteb-frontend / src / firebaseConfig.js View on Github external
import firebase from 'firebase'

var config = {
  apiKey: process.env.REACT_APP_API_KEY,
  authDomain: process.env.REACT_APP_AUTH_DOMAIN,
  databaseURL: process.env.REACT_APP_DATABASE_URL,
  projectId: process.env.REACT_APP_PROJECT_ID,
  storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID
}

firebase.initializeApp(config)

export const firebaseDB = firebase.database()
export const firebaseAuth = firebase.auth()
export const firebaseMessaging = firebase.messaging()
export const storage = firebase.storage()
github safeimuslim / push-notifications-next-js / utils / offline.js View on Github external
const config = {
    apiKey: '',
    authDomain: '',
    databaseURL: '',
    projectId: '',
    storageBucket: '',
    messagingSenderId: ''
  }
  /**
   * initializaation firebase
   */
  firebase.initializeApp(config)
  /**
   * initializaation firebase messaging
   */
  const messaging = firebase.messaging()

  /**
   * On load register service worker
   */
  window.addEventListener('load', () => {
    navigator.serviceWorker.register('sw.js').then((registration) => {
      /**
       * Successfully registers service worker
       */
      messaging.useServiceWorker(registration)
    })
      .then(() => {
        /**
         * request permission
         */
        return messaging.requestPermission()
github laqul / laqul / client / src / boot / firebase-init.js View on Github external
.then(registration => {
        firebase.messaging().useServiceWorker(registration)
        return Promise.resolve(true)
      })
  } else {