小编Bik*_*mat的帖子

限制对admin-sdk的firestore访问

我正在设计一个基于VueJs(用于UI)+ NodeJs(用于后端,将在Google Cloud Platform中运行)+ Firestore(用于auth +数据库)的应用程序(我们称之为TodoList应用程序).

我已经浏览了Google的大量文档(有时是多余的!)来实现应该有用的东西,但我不确定它是否符合生产要求.

情况:

  • 由于基于密码的Firebase身份验证(以及用户的凭据,包括他的accessToken,存储在我的Vuex商店中),用户已在我的VueJs应用程序上登录.
  • Firebase Admin SDK正在我的后端运行.
  • 我的VueJs应用程序正在请求我的后端.
  • 后端验证客户端请求中发送的accessToken
  • 由于Admin SDK,我的后端请求我的Firestore数据库

我在Firestore数据库上设置了一些安全规则:

service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId}/{document=**} {
      allow read, write: if request.auth.uid == userId;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

这样我就不希望任何记录的用户访问其他用户的数据.

题:

由于Firebase Admin SDK对我的Firestore数据库具有完全权限,因此如何确保不会出现任何安全问题.现在,我只是验证请求中发送的accessToken到我的后端,但......有些东西让我觉得这个错了!

码:

在客户端:

auth.onAuthStateChanged((user) => {
  if (user) {
    // Save the user credentials
  }
}
Run Code Online (Sandbox Code Playgroud)

在服务器端:

// idToken comes from the client app (shown above)
// …
Run Code Online (Sandbox Code Playgroud)

authentication node.js firebase firebase-admin google-cloud-firestore

7
推荐指数
2
解决办法
1381
查看次数

在Firebase客户端应用程序中实现可调用的云功能

我最近发现了Firebase可调用函数,它允许我从客户端调用HTTPS触发器(和auth()支持).

我很难在我现有的Firebase Web客户端应用程序中实现这一新功能.

我有一些运行的云函数,其中有一些我希望转换为HTTPS可调用函数的HTTPS函数(带有functions.https.onCall).

文件表明:

Set up your client development environment
<script src="https://www.gstatic.com/firebasejs/4.12.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.12.0/firebase-functions.js"></script>
Run Code Online (Sandbox Code Playgroud)

我的代码是:

import firebase from 'firebase';
import 'firebase/firestore';

const firebaseApp = firebase.initializeApp({
  apiKey: '....',
  authDomain: '....',
  databaseURL: '....',
  projectId: '....',
  storageBucket: '....',
  messagingSenderId: '....',
});

const db = firebaseApp.firestore();
const auth = firebaseApp.auth();
const functions = firebaseApp.functions();

export { db, auth, functions };
Run Code Online (Sandbox Code Playgroud)

当我运行我的应用程序时,我收到以下错误:

Uncaught TypeError: firebaseApp.functions is not a function
Run Code Online (Sandbox Code Playgroud)

我曾尝试yarn add firebase-functions,然后import 'firebase-functions但随后的应用需要firebase-admin.我担心这对客户端应用来说太过分了,所以我可能会走错方向.

有人可以帮我解决这个问题吗?(!)这个问题是 …

firebase google-cloud-functions

3
推荐指数
1
解决办法
2059
查看次数

检查位是否已在C中切换

我正在进行按位操作(在C中),我想知道如何检查一个位是否在前一个值和新值之间切换.

Example :
    oldValue = 0x0FF //0000 1111 1111 in binary
    newValue = 0x100 //0001 0000 0000 in binary
Run Code Online (Sandbox Code Playgroud)

在这个例子中,我想检查bit8(第9位)是否已从0切换到1.

我知道如果我想知道是否设置了一下,可以使用:

value & (1 << 8)
Run Code Online (Sandbox Code Playgroud)

那么,这是正确的吗?:

if( (oldValue & (1 << 8)) == (newValue & (1 << 8)) ) //return 0 if toggled
Run Code Online (Sandbox Code Playgroud)

c bit-manipulation toggle

2
推荐指数
1
解决办法
733
查看次数

在电子应用程序中使用vue + webpack引用静态资产

我是vuejs + webpack + electron的新手,我正在用这些工具开始一个新项目.

我很难在我的标签中检索资产的路径.

我的项目结构如下:

/my-project
  /app
    /components
      componentA.vue
      ...
    App.vue
    main.js
  /dist
  /assets
    logo.png
  package.json
  webpack.config.js
  ...
Run Code Online (Sandbox Code Playgroud)

我的webpack.config.js看起来像:

module.exports = {
  // This is the "main" file which should include all other modules
  entry: './app/main.js',
  // Where should the compiled file go?
  output: {
    // To the `dist` folder
    path: './dist',
    // With the filename `build.js` so it's dist/build.js
    filename: 'build.js'
  },
  module: {
    loaders: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.js$/,
        loader: 'babel-loader', …
Run Code Online (Sandbox Code Playgroud)

webpack vue.js webpack-2 webpack-file-loader

1
推荐指数
1
解决办法
4001
查看次数