Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript firebase firestore节点js如何创建管理页面_Javascript_Node.js_Firebase_Google Cloud Firestore_Google Cloud Functions - Fatal编程技术网

Javascript firebase firestore节点js如何创建管理页面

Javascript firebase firestore节点js如何创建管理页面,javascript,node.js,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Firestore,Google Cloud Functions,我希望我的网站有一个管理页面,从那里只有我可以访问firestore数据库,并做不同的读写 目前在我的项目中,我正在使用云函数,但我不知道如何设置它,以便只有一个用户(我)可以从index.js访问一些云函数 目前看起来是这样的: const functions = require('firebase-functions'); // Import and initialize the Firebase Admin SDK. const admin = require('firebase-admi

我希望我的网站有一个管理页面,从那里只有我可以访问firestore数据库,并做不同的读写

目前在我的项目中,我正在使用云函数,但我不知道如何设置它,以便只有一个用户(我)可以从index.js访问一些云函数

目前看起来是这样的:

const functions = require('firebase-functions');
// Import and initialize the Firebase Admin SDK.
const admin = require('firebase-admin');
admin.initializeApp();

exports.getProfile = functions.https.onCall(async(data, context) => {
  ...  
  }
getProfile应该是一个任何人都可以访问的云函数,但除此之外,我希望其他读/写函数只能由一个用户(管理员和我)访问


我应该为管理员创建另一个项目吗?哪些会有自己的index.js用于云功能?

您可以在firebase控制台中设置firestore规则,并引用一些只有您才能访问的特定信息

创建新的firebase项目不是最佳解决方案

比如说 在firestore中,您可以设置规则,仅允许用户读取和写入特定数据。而您可以允许管理员进行读写操作


设置firebase auth用户后,您将获得uid,这可用于引用firestore规则中的管理员

您可以在firebase控制台中设置firestore规则,并引用一些只有您才能访问的特定信息

创建新的firebase项目不是最佳解决方案

比如说 在firestore中,您可以设置规则,仅允许用户读取和写入特定数据。而您可以允许管理员进行读写操作

设置firebase身份验证用户后,您将获得一个uid,这可用于引用firestore规则中的管理员

只有我可以访问firestore数据库的地方

  • 编写firebase云firestore规则,如下所示:

    允许读取:if request.auth.uid==“您的用户uid”; 允许写入:if request.auth.uid==“您的用户uid”

  • 只有一个用户(me)可以从index.js访问一些云函数

    getProfile应该是任何人都可以访问的云函数

    这些都是矛盾的,但我猜你只允许公众访问一个云功能,而其他所有功能都只允许你访问。您可以在cloud函数中使用上下文参数访问请求的用户uid,如下所示并限制访问:

    if (context.auth.uid === "your-user-uid"){
        runFunction();
        return {
            error: false,
            msg: "Function run was successful."
        }
    }
    else{
        return {
            error: true,
            msg: "You do not have admin privilege to access this cloud function."
        }
    }
    
    只有我可以访问firestore数据库的地方

  • 编写firebase云firestore规则,如下所示:

    允许读取:if request.auth.uid==“您的用户uid”; 允许写入:if request.auth.uid==“您的用户uid”

  • 只有一个用户(me)可以从index.js访问一些云函数

    getProfile应该是任何人都可以访问的云函数

    这些都是矛盾的,但我猜你只允许公众访问一个云功能,而其他所有功能都只允许你访问。您可以在cloud函数中使用上下文参数访问请求的用户uid,如下所示并限制访问:

    if (context.auth.uid === "your-user-uid"){
        runFunction();
        return {
            error: false,
            msg: "Function run was successful."
        }
    }
    else{
        return {
            error: true,
            msg: "You do not have admin privilege to access this cloud function."
        }
    }
    

    您是否使用互联云功能构建网站?您是否使用互联云功能构建网站?