Firebase Authentication
async createUser() { try { await this.$fireAuth.createUserWithEmailAndPassword( 'foo@foo.foo', 'test' ) } catch (e) { alert(e) } }
This will throw a password error coming from Firebase, but proves the point.
Firebase Firestore
async writeToFirestore() { const messageRef = this.$fireStore.collection('message').doc('message') try { await messageRef.set({ message: 'Nuxt-Fire with Firestore rocks!' }) } catch (e) { alert(e) return } alert('Success.') }
async readFromFirestore() { const messageRef = this.$fireStore.collection('message').doc('message') try { const messageDoc = await messageRef.get() alert(messageDoc.data().message) } catch (e) { alert(e) return } }
Firebase Functions
Might take some seconds.
async callTestFunction() { try { const res = await this.$fireFunc.httpsCallable('testFunction')() alert(res.data) } catch (e) { alert(e) return } }
Firebase Realtime Database
async writeToRealtimeDb() { const messageRef = this.$fireDb.ref('message') try { await messageRef.set({ message: 'Nuxt-Fire with Firebase Realtime Database rocks!' }) } catch (e) { alert(e) return } alert('Success.') }
async readFromRealtimeDb() { const messageRef = this.$fireDb.ref('message') try { const snapshot = await messageRef.once('value') alert(snapshot.val().message) } catch (e) { alert(e) return } }
Firebase Storage
async uploadFile() { const storageRef = this.$fireStorage.ref().child('message.txt') const message = 'Nuxt-Fire with Firebase Storage rocks!' try { const snapshot = await storageRef.putString(message) alert('File uploaded.') } catch (e) { alert(e.message) } }
async getFileUrl() { const storageRef = this.$fireStorage.ref().child('message.txt') try { const url = await storageRef.getDownloadURL() alert(`The file can be found here: ${url}`) } catch (e) { alert(e.message) } }
Firebase Performance
Firebase Analytics
async logEvent() { try { await this.$fireAnalytics.logEvent('analytics_button_clicked') } catch (e) { alert(e) } }
This will log an event in Firebase Analytics.
Firebase RemoteConfig
async readRemoteConfig() { try { await this.$fireConfig.fetchAndActivate(); } catch (e) { alert(e); return; } const exampleMessage = await this.$fireConfig.getValue("exampleMessage"); alert( `Success. Read RemoteConfig parameter 'exampleMessage' is: ${exampleMessage._value}` ); }
Firebase Messaging
ID Token:
Vuex Store
Tests if fireXXX objects can be accessed in a vuex store action.