Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
// Create a storage ref
const fileName = `${file.name.split('.')[0]}-${randomStringGenerator()}.${file.name.split('.')[1]}`;
const storageRef = app(environment.firebase.projectId).storage().ref(`${folderName || this.folderName}/${fileName}`);
// Upload file
const task: storage.UploadTask = storageRef.put(file, {
cacheControl: 'public,max-age=300'
});
task.on(storage.TaskEvent.STATE_CHANGED, (snapshot: storage.UploadTaskSnapshot) => {
onProgress(Math.round((snapshot.bytesTransferred / snapshot.totalBytes) * 100));
switch (snapshot.state) {
case storage.TaskState.PAUSED:
break;
case storage.TaskState.RUNNING:
break;
}
handleProviderClick(provider){
const firebaseProvider = this.firebaseProviders[provider];
firebase.auth(firebase.app(FIREBASE_APP_NAME)).signInWithPopup(firebaseProvider).then(function(result) {
}).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
});
}
function FirebaseClient(firebaseConfig) {
this.firebaseConfig = firebaseConfig;
this.resources = {};
if (!firebase.apps.length) {
this.app = firebase.initializeApp(firebaseConfig);
}
else {
this.app = firebase.app();
}
this.db = this.app.firestore();
}
FirebaseClient.prototype.parseFireStoreDocument = function (doc) {
function ObtainFirebaseApp(firebaseConfig: {}, options: RAFirebaseOptions) {
if (options.app) {
return options.app;
}
const isInitialized = !!firebase.apps.length;
if (isInitialized) {
const app = firebase.app();
return app;
} else {
const app = firebase.initializeApp(firebaseConfig);
return app;
}
}
getFirebaseApp(props = this.props, context = this.context) {
return props.firebaseApp || context.firebaseApp || firebase.app()
}
constructor(props, context) {
super(props, context)
this.firebaseApp = props.firebaseApp || context.firebaseApp || firebase.app()
this.ref = path => this.firebaseApp.database().ref(path)
this.state = {
subscriptionsState: null,
}
}
import firebase from 'firebase/app';
import 'firebase/firestore';
const config = {
apiKey: 'AIzaSyD-sz6tSPCKKhQBJnl1SuAzrnMktnMOFSI',
authDomain: 'tanam-dev.firebaseapp.com',
databaseURL: 'https://tanam-dev.firebaseio.com',
projectId: 'tanam-dev',
storageBucket: 'tanam-dev.appspot.com',
messagingSenderId: '2622678578'
};
const firebaseApp = !firebase.apps.length
? firebase.initializeApp(config)
: firebase.app();
const firestore = firebaseApp.firestore();
firestore.settings({ timestampsInSnapshots: true });
export { firestore };
const initializeApp = config => {
firebase.initializeApp(config)
return firebase.app()
}
async handleRemove(key, media){
const {orkan} = this.props;
if(!confirm('are you sure?')){
return;
}
let fileRef = firebase.storage(firebase.app(FIREBASE_APP_NAME)).ref(media.fullPath);
fileRef.delete();
const path = MEDIA_KEY_NAME + '/' + this.getMediaType(media.mimeType) + '/' + key;
orkan.store.remove(path);
}
constructor() {
let app = firebase.apps.length !== 0 ? firebase.app() : firebase.initializeApp(config.firebase);
this.auth = app.auth();
this.db = app.database();
}
}