How to use the @firebase/app.firebase.messaging function in @firebase/app

To help you get started, we’ve selected a few @firebase/app 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 Sitecore / Sitecore.HabitatHome.Omni / fitness / app / src / services / SubscriptionService.js View on Github external
const getMessagingToken = async () => {
  try {
    const messaging = firebase.messaging();
    await messaging.requestPermission();
    const token = await messaging.getToken();
    // TODO: debugging
    console.log({ token });
    return token;
  } catch (error) {
    console.error(error);
    return null;
  }
};
github hand-dot / taskontable / src / utils / util.js View on Github external
const parser = new UAParser();
const browserName = parser.getBrowser().name;
const osName = parser.getOS().name;
const deviceType = parser.getDevice().type;

let database;
let auth;
let messaging;
let storage;
if (process.env.NODE_ENV !== 'test') {
  firebase.initializeApp(firebaseConf);
  database = firebase.database();
  auth = firebase.auth();
  if (constants.SUPPORTEDBROWSERS.indexOf(browserName) >= 0 && osName !== 'iOS') { // safari,iosではエラーになるため
    messaging = firebase.messaging();
  }
  storage = firebase.storage();
}

export default {
  /**
   * firebaseのdatabaseを返します。
   */
  getDatabase() {
    return database;
  },
  /**
   * firebaseのauthを返します。
   */
  getAuth() {
    return auth;
github Sitecore / Sitecore.HabitatHome.Omni / fitness / app / src / services / SubscriptionService.js View on Github external
export const initializeFirebase = callback => {
  try {
    const senderId = process.env.REACT_APP_FIREBASE_SENDER_ID;
    if(!senderId){
      throw new Error("FIREBASE_SENDER_ID is missing. Please add it to environment variables.");
    }

    firebase.initializeApp({ messagingSenderId: senderId});
    const messagingKey = process.env.REACT_APP_FIREBASE_MESSAGING_PUSH_KEY;
    if(!messagingKey){
      throw new Error("FIREBASE_MESSAGING_PUSH_KEY is missing. Please add it to environment variables.");
    }
    const messaging = firebase.messaging();
    messaging.usePublicVapidKey(messagingKey);
    messaging.onMessage(function(payload) {
      console.log("Message received. ", payload);
      callback(payload);
    });
  } catch (err) {
    console.error("Unable to initialize firebase. " + err);
  }
};