angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.64k stars 2.2k forks source link

Registration failed - push service error #2475

Closed pgedzba closed 3 years ago

pgedzba commented 4 years ago

Version info

Angular:9.1.9

Firebase:7.14.4

AngularFire:6.0.0

Other (e.g. Ionic/Cordova, Node, browser, operating system):Brave/Chrome

How to reproduce these conditions

After logging in I am calling this function: image It returns an error on line 57, which is described below. If I remove requestToken and change it to requestPermission then there is no error, but I am not receiving any messages.

I have VAPID key from firebase cloud messaging.

Below is full messaging.service.ts ` @Injectable() export class MessagingService {

currentMessage = new BehaviorSubject(null);

constructor(
    private angularFireDB: AngularFireDatabase,
    private angularFireAuth: AngularFireAuth,
    private angularFireMessaging: AngularFireMessaging,
    private httpClient: HttpClient) {
    this.angularFireMessaging.usePublicVapidKey(environment.VAPID_KEY);
    // this.angularFireMessaging.messaging.subscribe(
    //     (_messaging) => {
    //         _messaging.onMessage = _messaging.onMessage.bind(_messaging);
    //         _messaging.onTokenRefresh = _messaging.onTokenRefresh.bind(_messaging);
    //     }
    // );
}

/**
 * update token in firebase database
 *
 * @param userId userId as a key
 * @param token token as a value
 */
updateToken(userId, token) {
    // we can change this function to request our backend service
    this.angularFireAuth.authState.pipe(take(1)).subscribe(
        () => {
            const data = {};
            data[userId] = token;
            this.httpClient.post(environment.API_URL + '/api/device_tokens', { token }).subscribe();
            this.angularFireDB.object('fcmTokens/').update(data);
        });
}

/**
 * request permission for notification from firebase cloud messaging
 * 
 * @param userId userId
 */
requestPermission(userId) {
    this.angularFireMessaging.requestToken.subscribe(
        (token) => {
            this.updateToken(userId, token);
        },
        (err) => {
            console.error('Unable to get permission to notify.', err);
        }
    );
}

/**
 * hook method when new notification received in foreground
 */
receiveMessage() {
    this.angularFireMessaging.messages.subscribe(
        (payload) => {
            this.currentMessage.next(payload);
        });
}

} `

Debug output

Errors in the JavaScript console messaging.service.ts:57 Unable to get permission to notify. DOMException: Registration failed - push service error

image

Expected behavior

Notifications should register

Actual behavior

I get an error

naveedahmed1 commented 4 years ago

Any update on this?

pgedzba commented 4 years ago

I didn't find the solution yet

naveedahmed1 commented 4 years ago

Its strange that its working on some devices and throwing this error on other devices.

naveedahmed1 commented 4 years ago

@pgedzba can you please check if it's working on Firefox on same machine? In my case it's working fine on Firefox but throwing error in Chrome.

pgedzba commented 4 years ago

I can not install any other browser on this machine

shadow1349 commented 3 years ago

I've been having a similar problem specifically on Brave:

push service error

This one has been particularly annoying because I can't use any of my callable functions on Brave without getting this exact same error which is just plain weird.

I can say this is not reproducible on FireFox.

jamesdaniels commented 3 years ago

Closing here in favor of the js sdk bug, as it's not AngularFire specific.