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

B2B企業がCloudFunctionsで C2Cサービスに挑んだ話

TakeshiNishi
December 14, 2019

B2B企業がCloudFunctionsで C2Cサービスに挑んだ話

B2B企業受託がメインのIT企業が、CloudFunctionsとFirebaseを使って、BtoC、CtoCに挑んだ話です。

これからサーバーレス、Firebase触ってみたい方向けの資料になります。

Firebaseの開発の詳細は、こちらのアドベントカレンダーをご参照ください。
https://qiita.com/advent-calendar/2019/diffeasy24

TakeshiNishi

December 14, 2019
Tweet

More Decks by TakeshiNishi

Other Decks in Technology

Transcript

  1. $MPVE
 %/4 $MPVE
 $%/ $MPVE
 -PBE #BMBODJOH $PNQVUF &OHJOF $PNQVUF

    &OHJOF $MPVE
 42- $MPVE
 4UPSBHF w ϑϩϯτΤϯυϓϩάϥϜ w ը૾ͳͲ੩తίϯςϯπ w ن໛ʹԠͯ͡ෛՙ෼ࢄ w όοΫΤϯυϓϩάϥϜ w ن໛ʹԠͯ͡ෳ਺୆ߏ੒ w ϩάϑΝΠϧ w ಈతϑΝΠϧ $MPVE
 .FNPSZTUPSF w 3FEJT w %#
  2. 'JSFCBTF6*ͰϩάΠϯը໘΋ <template> <firebase-auth /> </template> <script> import FirebaseAuth ɹɹ from

    "@/components/FirebaseAuth"; export default { name: "Login", components: { FirebaseAuth } }; </script>
  3. σʔλͷϧʔϧઃఆ͸ࡉ৺ͷ஫ҙΛ match /databases/{database}/documents { match /users/{uid} { allow update, delete:

    if request.auth.uid == uid; allow create, read : if request.auth.uid != null; } match /messages/{uid} { allow update, delete: if request.auth.uid == uid; allow create, read: if request.auth.uid != null; } }
  4. $MPVE'VODUJPOTͷ࣮ߦ exports.hello = https.onCall(async (data, context) => { }); exports.updateUser

    = https.onCall(async (data, context) => { }); exports.getUser = https.onCall(async (data, context) => { }); exports.sendPushMessage = firestore .document(“messages/{userId}") .onWrite(async (change, context) => { }); JOEFYKT
  5. $MPVE'VODUJPOTͷ࣮ߦ const hello = functions.httpsCallable("hello"); const result = await hello({

    name: "takeshi" }); this.message = result.data.message; ΫϥΠΞϯταΠυ exports.hello = https.onCall((data, context) => { return { message: `Hello, ${data.name}.`, uid: context.auth.uid }; }); αʔόʔαΠυ OPEFKT ೝূ৘ใͷऔಘ΋؆୯
  6. 'JSFTUPSFߋ৽ΛτϦΨʔʹ௨஌ exports.sendPushMessage = firestore .document("messages/{userId}") .onWrite(async (change, context) => {

    const data = change.after.data(); const previousData = change.before.data(); const userRef = await admin .firestore() .collection("users") .doc(context.params.userId); const userDoc = await userRef.get(); ߋ৽લޙͷ஋औಘ
  7. 'JSFTUPSFߋ৽ΛτϦΨʔʹ௨஌ const payload = { notification: { title: "௨஌λΠτϧ", body:

    "௨஌ຊจ" } }; admin .messaging() .sendToDevice(user.fcmToken, payload); ϓογϡ௨஌ૹ৴