Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import firebase from 'firebase';
import ReduxSagaFirebase from 'redux-saga-firebase';
import config from '../../config';
const FirebaseApp = firebase.initializeApp(config.firebase);
export const RSF = new ReduxSagaFirebase(FirebaseApp);
export const FirebaseDB = firebase.database();
// firebase.database.enableLogging(false, false);
export const FirebaseAuth = firebase.auth();
export const FirebaseMsg = firebase.messaging();
export const getFirebaseAuthProvider = provider => {
switch (provider) {
case 'facebook':
return new firebase.auth.FacebookAuthProvider();
case 'google':
return new firebase.auth.GoogleAuthProvider();
case 'github':
return new firebase.auth.GithubAuthProvider();
case 'twitter':
return new firebase.auth.TwitterAuthProvider();
default:
return null;
}
};
export const askForPermissioToReceiveNotifications = async () => {
try {
const messaging = firebase.messaging();
await messaging.requestPermission();
const token = await messaging.getToken();
console.log('user token: ', token);
return token;
} catch (error) {
console.error(error);
}
}
import * as firebase from 'firebase';
firebase.initializeApp({
apiKey: 'AIzaSyCBI49-UdKW6iyayFhOnGnq4gBthx-2xe8',
authDomain: 'yak-chat-779ce.firebaseapp.com',
databaseURL: 'https://yak-chat-779ce.firebaseio.com',
projectId: 'yak-chat-779ce',
storageBucket: 'yak-chat-779ce.appspot.com',
messagingSenderId: '812078557420'
});
const messaging = firebase.messaging();
export async function getNotificationToken() {
try {
const token = await messaging.getToken();
return token;
} catch (e) {
console.log('Failed to get token...', e);
}
return null;
}
const initNotifications = () => {
messaging.requestPermission()
.then(() => {
console.log('> Notification permission granted.');
function* requestPermissionSaga() {
const messaging = firebase.messaging()
try {
yield messaging.requestPermission()
const token = yield messaging.getToken()
yield put(setRegistrationToken(token))
} catch (error) {
console.warn('Notifications blocked')
}
}
const prodConfig = {
apiKey: '',
authDomain: '',
databaseURL: '',
storageBucket: '',
messagingSenderId: ''
};
const isProd = process.env.NODE_ENV === 'production';
const firebaseConfig = isProd ? prodConfig : stagingConfig;
firebase.initializeApp(firebaseConfig);
export const ref = firebase.database().ref();
export const firebaseAuth = firebase.auth;
export const storage = firebase.storage();
export const messaging = firebase.messaging();
import firebase from 'firebase'
var config = {
apiKey: process.env.REACT_APP_API_KEY,
authDomain: process.env.REACT_APP_AUTH_DOMAIN,
databaseURL: process.env.REACT_APP_DATABASE_URL,
projectId: process.env.REACT_APP_PROJECT_ID,
storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID
}
firebase.initializeApp(config)
export const firebaseDB = firebase.database()
export const firebaseAuth = firebase.auth()
export const firebaseMessaging = firebase.messaging()
export const storage = firebase.storage()
const config = {
apiKey: '',
authDomain: '',
databaseURL: '',
projectId: '',
storageBucket: '',
messagingSenderId: ''
}
/**
* initializaation firebase
*/
firebase.initializeApp(config)
/**
* initializaation firebase messaging
*/
const messaging = firebase.messaging()
/**
* On load register service worker
*/
window.addEventListener('load', () => {
navigator.serviceWorker.register('sw.js').then((registration) => {
/**
* Successfully registers service worker
*/
messaging.useServiceWorker(registration)
})
.then(() => {
/**
* request permission
*/
return messaging.requestPermission()
.then(registration => {
firebase.messaging().useServiceWorker(registration)
return Promise.resolve(true)
})
} else {