Removed mandatory loading of firebase messaging as it does not support Safari.

This commit is contained in:
Patrick Fic
2020-05-01 14:32:27 -07:00
parent 636e979fd0
commit 4699b10093
4 changed files with 21 additions and 11 deletions

View File

@@ -12,3 +12,7 @@ npx hasura console --admin-secret Dev-BodyShopAppBySnaptSoftware!
Migrating to Staging:
npx hasura migrate apply --up 10 --endpoint https://bodyshop-staging-db.herokuapp.com/ --admin-secret Staging-BodyShopAppBySnaptSoftware!
NGROK TEsting:
./ngrok.exe http https://localhost:5000 -host-header="localhost:5000"

View File

@@ -1,10 +1,9 @@
import { notification } from "antd";
import React, { Component } from "react";
import { messaging } from "../../firebase/firebase.utils";
import { withApollo } from "react-apollo";
import { UPDATE_FCM_TOKEN } from "../../graphql/user.queries";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { messaging } from "../../firebase/firebase.utils";
import { UPDATE_FCM_TOKEN } from "../../graphql/user.queries";
import { selectCurrentUser } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
currentUser: selectCurrentUser,
@@ -16,6 +15,8 @@ const mapDispatchToProps = (dispatch) => ({
class FcmNotificationComponent extends Component {
async componentDidMount() {
const { client, currentUser } = this.props;
if (!!!messaging) return; //Skip all of the notification functionality if the firebase SDK could not start.
messaging
.requestPermission()
.then(async function () {
@@ -31,7 +32,6 @@ class FcmNotificationComponent extends Component {
});
navigator.serviceWorker.addEventListener("message", (message) => {
const { payload } = message.data.firebaseMessaging;
// notification["info"]({ message: JSON.stringify(payload) });
navigator.serviceWorker.getRegistration().then((registration) =>
registration.showNotification(payload.notification.title, {
@@ -50,7 +50,7 @@ class FcmNotificationComponent extends Component {
}
render() {
return <div></div>;
return <span />;
}
}

View File

@@ -34,9 +34,16 @@ export const updateCurrentUser = (userDetails) => {
});
};
const messaging = firebase.messaging();
messaging.usePublicVapidKey(
// Project Settings => Cloud Messaging => Web Push certificates
"BBlvtEL73vYinkiAgK5t51jgDTYj6961OO_5niP4Q5py_l5yhTL8IGYkpONyMGoXs8ZTdVhEWsu3_IEXcW0cIIg"
);
let messaging;
try {
messaging = firebase.messaging();
messaging.usePublicVapidKey(
// Project Settings => Cloud Messaging => Web Push certificates
"BBlvtEL73vYinkiAgK5t51jgDTYj6961OO_5niP4Q5py_l5yhTL8IGYkpONyMGoXs8ZTdVhEWsu3_IEXcW0cIIg"
);
console.log("Firebase Messaging initialized successfully.");
} catch {
console.log("Firebase Messaging is likely unsupported.");
}
export { messaging };

View File

@@ -57,7 +57,6 @@ export function register(config) {
navigator.serviceWorker
.register("./firebase-messaging-sw.js")
.then(function (registration) {
console.log("FCM Registration :", registration);
console.log(
"FCM Registration successful, scope is:",
registration.scope