Created
April 3, 2020 21:19
-
-
Save omar-vasquez-dev/3ec8c026b90f3dbe83e180be36041ba5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { app, BrowserWindow } = require('electron') | |
const firebase = require('firebase'); | |
const firebaseConfig = { ... }; | |
const firebaseToken = '...'; | |
const fbApp = firebase.initializeApp(firebaseConfig); | |
const auth = fbApp.auth(); | |
const db = fbApp.firestore(); | |
const updateMyDoc = (fields) => { | |
return new Promise(async (resolve, reject) => { | |
try { | |
if (!auth.currentUser) { | |
throw new Error('Unable to update user roster, not logged in?'); | |
} | |
const userID = auth.currentUser.uid; | |
await db.doc(`tests/${userID}`).update(fields); | |
resolve(); | |
} catch (error) { | |
reject(error); | |
} | |
}); | |
} | |
const firebaseTest = async () => { | |
try { | |
await auth.signInWithCustomToken(firebaseToken); | |
console.log('all good, trying to write...'); | |
await updateMyDoc({ 'key2': 'value2' }); | |
await auth.signOut(); | |
} catch (error) { | |
console.error('Something went wrong:', error); | |
} | |
}; | |
app.on('ready', firebaseTest); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment