Authから始めるFirebaseの第一歩

44749d6ac5ca44e5325622593877c420?s=47 massyuu
February 21, 2019

 Authから始めるFirebaseの第一歩

44749d6ac5ca44e5325622593877c420?s=128

massyuu

February 21, 2019
Tweet

Transcript

  1. 4.

    'JSFCBTF"VUIFOUJDBUJPO • 'JSFCBTF͕ఏڙ͍ͯ͠ΔϢʔβʔೝূػೳ • ΞϓϦέʔγϣϯͷϢʔβʔΛ؆୯ʹೝূɾࣝผͯ͘͠ΕΔ • 4%,Λར༻͢Δ͔ɺ6*ϥΠϒϥϦʹΑΓ؆୯ʹ࣮૷͢Δ͜ͱ͕Մೳ • ༷ʑͳํ๏ͰͷೝূΛఏڙՄೳ •

    ϝʔϧΞυϨεʢˍύεϫʔυʣ • ి࿩൪߸ • 4/4ೝূʢ5XJUUFSɺ'BDFCPPLɺ(PPHMFɺ(JU)VCͳͲʣ • ύεϫʔυͳͲࣗલͷ%#ʹอଘ͠ͳ͍Ͱ͍͍ͷ͕ྑ͖ • ݸਓతʹҰ൪޷͖͔΋͠Εͳ͍αʔϏε  
  2. 6.

    'JSFCBTF6*"VUI • ެ͓ࣜ͢͢Ί • 6*ΛؚΊͨೝূػೳΛఏڙ • 6*΋ఏڙͯ͘͠ΕΔͷͰϩάΠϯपΓͷॲཧΛ·Δͬͱ'JSFCBTFʹ೚ͤΔ͜ͱ͕Ͱ͖Δ • (JU)VCʢ8FC༻ϦϙδτϦɾσϞϖʔδʣ •

    IUUQTHJUIVCDPNGJSFCBTFGJSFCBTFVJXFC • IUUQTGJSVJEFNPBDGJSFCBTFBQQDPN • ެࣜʹ͸"OESPJEɺJ04ɺ8&#ʢ+4ʣͰར༻Մೳͱ͍ͯ͠Δ • 3FBDU΍"OHVMBS༻ʹϥοϓ͞ΕͨϦϙδτϦ΋͋ͬͨΓ  
  3. 8.
  4. 12.

    GJSFCBTFͷϞδϡʔϧΛ࡞Δ   'JSFCBTFͷઃఆ΍ૢ࡞ΛϞδϡʔϧʹ·ͱΊ͓ͯ͘ // Initialize Firebase const config =

    { apiKey: ‘apiKey wo Kokoni input', authDomain: 'vue-fb-auth.firebaseapp.com', databaseURL: 'https://vue-fb-auth.firebaseio.com', projectId: 'vue-fb-auth', storageBucket: ‘', messagingSenderId: '813627810276' } export default { // FirebaseॳظԽ init() { firebase.initializeApp(config) firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION) }, // GoogleϩάΠϯॲཧ googleLogin() { // GoogleϩάΠϯͷॲཧ಺༰Λ͜͜ʹ }, ͱ͔ ͳͲͳͲ
  5. 13.

    ϩάΠϯɾϩάΞ΢τͷهड़   ྫ͑͹5XJUUFSϩάΠϯΛ࣮૷͢Δ৔߹ͷهड़͸͜Ε͚ͩ ϩάΞ΢τͷ࣮૷͸ ͰऴΘΔͷͰΊͬͪΌ؆୯ ͋ͱ͸͜ΕΛίϯϙʔωϯτଆͰར༻͢Δ͚ͩ // ϩάΞ΢τॲཧ logout()

    { firebase.auth().signOut() }, // TwitterϩάΠϯॲཧ twitterLogin() { const Provider = new firebase.auth.TwitterAuthProvider() firebase.auth().signInWithPopup(Provider) },
  6. 16.

    GJSFCBTF6*ͷϞδϡʔϧΛ࡞Δ   'JSFCBTFͱ'JSFCBTF6*ͷઃఆ΍ૢ࡞ΛϞδϡʔϧʹ·ͱΊ͓ͯ͘ 'JSFCBTFͷઃఆ͸4%,Λ࢖͏࣌ͱಉ༷ // Initialize Firebase const config

    = { apiKey: ‘apiKey wo Kokoni input', authDomain: 'vue-fb-auth.firebaseapp.com', databaseURL: 'https://vue-fb-auth.firebaseio.com', projectId: 'vue-fb-auth', storageBucket: ‘', messagingSenderId: '813627810276' }
  7. 17.

    GJSFCBTF6*ͷϞδϡʔϧΛ࡞Δ   'JSFCBTF6*ͷઃఆ͸͜Μͳײ͡ const uiConfig = { // ϙοϓΞοϓදࣔ

    signInFlow: 'popup', // ϩάΠϯ੒ޭ࣌ͷ໭ΓURL signInSuccessUrl: '/auth', // ϩάΠϯͷํ๏ signInOptions: [ firebase.auth.GoogleAuthProvider.PROVIDER_ID, firebase.auth.TwitterAuthProvider.PROVIDER_ID, firebase.auth.EmailAuthProvider.PROVIDER_ID ], // ϦμΠϨΫτͷઃఆ callbacks: { signInSuccessWithAuthResult: () => { return true } } } ͦͷଞʹ΋͍͔ͭ͘Φϓγϣϯͷઃఆ͕͋Γ·͢
  8. 20.

    ·ͱΊͱॴײ   • 4%,ɺ6*ͷ͍ͣΕ΋࣮૷ࣗମ͸௒؆୯ • ͬ͘͞ͱϩάΠϯॲཧΛ࡞Γ͍ͨͳΒ6*࢖͏ͷ΋͋Γ • ϨϯμϦϯάʹएׯͷϥά͕͋ΔͷͰɺݟͤํ͔ͬ͠Γͱ •

    ೔ຊޠͷ৘ใ͸4%,ͷํ͕ଟΊΈ͍ͨ • αʔϏεͷσβΠϯʹدͤΔͳΒ4%,࢖͏ํ͕ແ೉ͳͷ͔ͳ • ͋ͱɺ3VMFTͷઃఆ͸େࣄ