Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

397
Visualizações
FCM - How to send and display notification from vue app

I have an app that is running on firebase BaaS. I need to send notifications to a specific user when an action occur and at the same time retrive the notification to display it.

I've followed some guide and the documentations to implement it in my service worker and I was able to get a notification logged in console with this code when using the firebase console.


importScripts('https://www.gstatic.com/firebasejs/9.1.3/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/9.1.3/firebase-messaging-compat.js');

firebase.initializeApp({
    apiKey: "...",
    authDomain: "...firebaseapp.com",
    databaseURL: "https://...-default-rtdb.firebaseio.com",
    projectId: "...",
    storageBucket: "...appspot.com",
    messagingSenderId: "...",
    appId: "...",
    measurementId: "..."
});

// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();

messaging.onBackgroundMessage( (payload) => {
    console.log('[firebase-messaging-sw.js] Received background message ', payload);
    // Customize notification here for 'data' key
    let { data } = payload
    if( data && data.title && data.body ) {
        const notificationTitle = data.title || 'Test title';
        const notificationOptions = {
            body: data.body || 'Test body',
        };
  
        self.registration.showNotification(notificationTitle, notificationOptions);
    }
});
  
self.addEventListener('notificationclick', (event) => {
    let { notification } = event;
    // this event will not be occoured by notication of FCM 'notification' key
    console.log('[firebase-messaging-sw.js]  Notification clicked: ', event);
    notification.close()
}); 

Since the final user will not have access to the firebase FCM console, how I can add the ability to send a notification from my vue app, and how I can retrive it when a notification is recived?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda