Skip to content
Hunter Wu edited this page Sep 30, 2022 · 3 revisions

Project

firebase use <project-id>

Forestore

                                  get()
  db.collection()   =====> ColRef -----> QuerySnapshots
                           /\ ||                 ||
                     col() || || doc()           || .docs
                   .parent || || .parent         ||
                           || ||                 \/
                           || \/   get() (QueryDocumentSnapshot)   data()
  collection.doc()  =====> DocRef -----> DocumentSnapshot        ========> {obj}
                                  <=====
                                   .ref

Cloud functions - local

GOOGLE_APPLICATION_CREDENTIALS=/home/wmh/workspaces/firebase/hunw/hunw-b9da29320702.json
firebase experimental:functions:shell
importAccount({type: 'wallet', name: 'ETH', address: '0x42f844bd520d63e4a7f1490a94deea1737f0a584'}, {params: {uid: 'ZgxIslDiaLbbb5BwOlx2', accountId: 'TfLRRlLTCnl82113IMWy'}})
importAccount({type: 'wallet', name: 'ETH', address: '0x74660414dfae86b196452497a4332bd0e6611e82'}, {params: {uid: 'ZgxIslDiaLbbb5BwOlx2', accountId: 't1'}})

two types of functions

import * as functions from "firebase-functions";

const result = {
  "AA": 1,
  "BBB": 222,
};

const type1 = functions
    .region("asia-east1")
    .https.onRequest(
        async (request, response) => {
          console.log(request.headers["authorization"]);
          response.send(result);
        });

const type2 = functions
    .region("asia-east1")
    .https.onCall(
        async (data, context) => {
          // if ( ! context.auth) {
          //   return {"error": "Failed to auth"};
          // }
          console.log("data:", data);
          console.log("context:", context);
          return result;
        });

export {type1, type2};
Clone this wiki locally