2

I have a subscribe button I've written a small function but am getting the error above

methods: {
    subscribe(){
        firebase.messaging.requestPermission()
                          .then(() => {
                              console.log('Notification permission granted.');
                              return this.messaging.getToken();
                          })
    }
}

Button

<button id="subscribe" @click="subscribe">Subscribe</button>
2
  • 2
    It looks like you haven't integrated the FCM JavaScript SDK correctly. Commented Jan 19, 2020 at 21:48
  • 1
    where am supposed to intergrate it? Commented Jan 19, 2020 at 21:51

1 Answer 1

1

1.Install firebase to your project:

npm install --save firebase

2.Then add the messaging module in your project. E.g. index.js file.

import 'firebase/messaging'

3.Then use the messaging in your component:

import firebase from 'firebase';

...

methods: {
    subscribe () {
        const messaging = firebase.messaging();
        messaging.requestPermission().then(
            ...
        );
    }
}

Just remember that the Firebase SDK is modular, Although you reference everything from the firebase package, If you don't include the referencing module (messaging in this case) in your final bundle, the firebase will complain about it missing.

Take a look at here for more information: https://firebase.google.com/docs/web/setup

Sign up to request clarification or add additional context in comments.

5 Comments

am getting the error TypeError: firebase__WEBPACK_IMPORTED_MODULE_9___default.a.messaging.requestPermission is not a function"
Did you do the 2nd step? And don't forget that messaging is a function not a property. So you should do it like this: firebase.messaging().requestPermission()
And did you try firebase.messaging().requestPermission() instead of firebase.messaging.requestPermission()?
firebase.messaging().requestPermission() is throwing an error Deprecated symbol used, consult docs for better alternative
That's because requestPermission() method is deprecated. Take a look at here: firebase.google.com/docs/reference/js/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.