Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Authから始めるFirebaseの第一歩

massyuu
February 21, 2019

 Authから始めるFirebaseの第一歩

massyuu

February 21, 2019
Tweet

More Decks by massyuu

Other Decks in Technology

Transcript

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

    ϝʔϧΞυϨεʢˍύεϫʔυʣ • ి࿩൪߸ • 4/4ೝূʢ5XJUUFSɺ'BDFCPPLɺ(PPHMFɺ(JU)VCͳͲʣ • ύεϫʔυͳͲࣗલͷ%#ʹอଘ͠ͳ͍Ͱ͍͍ͷ͕ྑ͖ • ݸਓతʹҰ൪޷͖͔΋͠Εͳ͍αʔϏε  
  2. 'JSFCBTF6*"VUI • ެ͓ࣜ͢͢Ί • 6*ΛؚΊͨೝূػೳΛఏڙ • 6*΋ఏڙͯ͘͠ΕΔͷͰϩάΠϯपΓͷॲཧΛ·Δͬͱ'JSFCBTFʹ೚ͤΔ͜ͱ͕Ͱ͖Δ • (JU)VCʢ8FC༻ϦϙδτϦɾσϞϖʔδʣ •

    IUUQTHJUIVCDPNGJSFCBTFGJSFCBTFVJXFC • IUUQTGJSVJEFNPBDGJSFCBTFBQQDPN • ެࣜʹ͸"OESPJEɺJ04ɺ8&#ʢ+4ʣͰར༻Մೳͱ͍ͯ͠Δ • 3FBDU΍"OHVMBS༻ʹϥοϓ͞ΕͨϦϙδτϦ΋͋ͬͨΓ  
  3. 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ϩάΠϯͷॲཧ಺༰Λ͜͜ʹ }, ͱ͔ ͳͲͳͲ
  4. ϩάΠϯɾϩάΞ΢τͷهड़   ྫ͑͹5XJUUFSϩάΠϯΛ࣮૷͢Δ৔߹ͷهड़͸͜Ε͚ͩ ϩάΞ΢τͷ࣮૷͸ ͰऴΘΔͷͰΊͬͪΌ؆୯ ͋ͱ͸͜ΕΛίϯϙʔωϯτଆͰར༻͢Δ͚ͩ // ϩάΞ΢τॲཧ logout()

    { firebase.auth().signOut() }, // TwitterϩάΠϯॲཧ twitterLogin() { const Provider = new firebase.auth.TwitterAuthProvider() firebase.auth().signInWithPopup(Provider) },
  5. 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' }
  6. 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 } } } ͦͷଞʹ΋͍͔ͭ͘Φϓγϣϯͷઃఆ͕͋Γ·͢
  7. ·ͱΊͱॴײ   • 4%,ɺ6*ͷ͍ͣΕ΋࣮૷ࣗମ͸௒؆୯ • ͬ͘͞ͱϩάΠϯॲཧΛ࡞Γ͍ͨͳΒ6*࢖͏ͷ΋͋Γ • ϨϯμϦϯάʹएׯͷϥά͕͋ΔͷͰɺݟͤํ͔ͬ͠Γͱ •

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