ElectronでFirebaseを使ってみた(仮)

 ElectronでFirebaseを使ってみた(仮)

ElectronでFirebaseを使ってみました。

1d42b38276c3d2c7cc931fa444c13488?s=128

Masaya Nasu

June 03, 2016
Tweet

Transcript

  1. ElectronͰFirebaseΛ࢖ͬͯ ΈΔʢԾʣ Gotanda.js #4 in Retty

  2. ࣗݾ঺հ • Github @nasum • twitter @tomato360

  3. Electron • ݴΘͣͱ஌ΕͨGithub੡ͷϑϨʔϜϫʔΫ • ࠷ۙ1.0͕ϦϦʔε͞Ε·ͨ͠ • ΋͏1.2.1ʹͳͬͯΔɻૣ͕͞ා͍ • ηΩϡϦςΟେมͳΠϝʔδ
 ElectronΞϓϦͷXSSͰrm

    -fr /Λ࣮ߦ͢Δ
 http://qiita.com/akameco/items/cc6fc949e7c9f0d1a42a

  4. Firebase • Google͕ങऩͨ͠BaaS • ϦΞϧλΠϜʹσʔλΛಉظ͢ΔͷʹڧΈͷ ͋ΔαʔϏε • Google IO Ͱϩάղੳ΍ϓογϡ௨஌ͷػೳ

    ͕௥Ճ͞Εͯ࿩୊
  5. ૊Έ߹Θͤͨಈػ • Electron΋1ܥʹͳֶͬͨ͠ͼ௚͢ࠒ߹͍ • EvernoteͷΑ͏ͳ΋ͷΛ࡞Γ͔ͨͬͨ • σʔλΛͲ͏ཷΊΔ͔ʹ೰Μͩ • nedb 


    https://github.com/louischatriot/nedb • electron-json-storage 
 https://github.com/jviotti/electron-json-storage • etc…etc… • Firebaseͷrealtime databaseΛ༻͍Ε͹͍͚ͦ͏
  6. FirebaseͷWeb൛ͰͰ͖Δ͜ͱ • Authentication • Realtime Database • Storage • Hosting

    • Cloud Messaging ElectronͰ࢖͑ͦ͏
  7. ஫ҙɿͣͬͱܯࠂ͕Ͱ·͢

  8. ElectronͰAuth • ElectronͰ͸Google΍TwitterɺFacebookͷೝূ͸࢖͑ͳ͍ • origin͕file://͔ͩΒઃఆͰ͖ͳ͍ • CordovaͰࣅͨΑ͏ͳ͜ͱͰ೰ΜͰ͍Δਓ͕͍ͨ
 https://groups.google.com/forum/#!topic/firebase-talk/ eUzTjj8mVa4 •

    signInWithEmailAndPasswordΛ࢖͑͹ೝূ͸ग़དྷΔ
 https://firebase.google.com/docs/auth/web/password- auth#before_you_begin
  9. Ϣʔβ࡞੒ var auth = firebase.auth(); auth.createUserWithEmailAndPassword(email, password).then(function(){ console.log('ok') var uid

    = auth.currentUser.uid; console.log(uid) writeUserData(uid, "hoge", email); }).catch(function(error) { // Handle Errors here. var errorCode = error.code; var errorMessage = error.message; // ... });
  10. Ϣʔβೝূ var auth = firebase.auth(); auth.signInWithEmailAndPassword(email, password).then(function(){ console.log('ok') var uid

    = auth.currentUser.uid; console.log(uid) }).catch(function(error) { // Handle Errors here. var errorCode = error.code; var errorMessage = error.message; console.log(errorCode); console.log(errorMessage); });
  11. ೝূ݁Ռ

  12. ೝূ৘ใ͸LocalStorageʹೖΔ

  13. ೝূ͸͏·͍ͬͨͧ͘ʂ
 ʢͰ΋ݸਓ༻్Ͱೝূ͸࢖Θͳ͍͔΋Ͷʂʣ

  14. Realtime Database • ίϯιʔϧͰϧʔϧΛܾΊΔඞཁ͕͋Δ • ݁ߏෳࡶͰ׳ΕΔ·Ͱେม • FirebaseͷRulesΛཧղ͢Δ
 http://qiita.com/laco0416/items/ b068ab0cf19a26f0992d

  15. ࢼ͠ʹ࡞ͬͨϧʔϧ

  16. ϧʔϧ͸ςετ΋Ͱ͖Δ

  17. realtime databaseʹอଘ͢Δ ίʔυ var auth = firebase.auth(); var uid =

    auth.currentUser.uid; var obj = { "title": "test", "description": "description" }; //σʔλΛηοτ͢Δ firebase.database().ref('documents/' + uid).push(obj); //σʔλͷҰཡΛऔಘ͢Δ firebase.database().ref('documents/' + uid).once('value').then(function(snapshot) { console.log(snapshot.val()); }); //σʔλͷมߋΛݕ஌͠දࣔ͢Δ firebase.database().ref('documents/' + uid).on('value', function(snapshot) { console.log(snapshot.val()); });
  18. ಈ͔ͯ͠ΈΔ

  19. realtime database΋͏·͘ ͍͖ͦ͏ʂ

  20. Ͱ΋͜͜Ͱ࣌ؒ੾Ε storageͱ͔΋ࢼ͔ͨͬͨ͠

  21. ·ͱΊ • ೝূ͸ଞͷαʔϏεͷOAuth࢖͑ͳ͍͚Ͳemail͔ͭͬͨೝূ͸ग़ དྷΔ • realtime database͸บ͕͋Δ • ϦΞϧλΠϜͰߋ৽͞ΕΔ͔Βຊ౰͸νϟοτ޲͚ͩΑͶ •

    ࣮͸ೝূͳ͠Ͱ࢖͑Δ • ܯࠂ͕ग़ଓ͚Δ͔Βݸਓ༻్Ͱ࢖͓͏ʂ • ࠷ऴతʹElectron͋Μ·Γؔ܎ͳ͘ͳͬͪΌͬͨ