title: Error 7: Missing or insufficient permissions cloud functions/firestore
body: <p>I am writing an app using firebase as a backend, and I am trying to write to the database, but am getting "Error 7:  Missing or insufficient permissions."  Someone told me cloud functions bypasses the firebase permissions, so I'm not sure what could be causing this error.  Can someone please take a look?</p>
  
  <p>Here are my permissions:</p>
  
  <pre><code>rules_version = '2';
  service cloud.firestore {
    match /databases/{database}/documents {
      match /{document=**} {
        allow read, write: if true;
      }
    }
  }
  </code></pre>
  
  <p>and here is my code:</p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  var express = require('express');
  admin.initializeApp(functions.config().firebase);
  
  const app = express();
  
  let db = admin.firestore();
  
  app.get('/helloworld', (req, res) =&gt; res.send('Hello World!'));
  
  app.post('/signup', (req, res) =&gt; {
  
  
    var email = req.body.email;
    var username = req.body.username;
    var password = req.body.password;
  
  
    //creating document.  Here is where it isn't working
  
    let docRef = db.collection('UsersMain').doc('firstdoc');
  
      let data = {
      Email: 'a@gmail.com',
      UserName: 'Matt'
    };
  
    let setDoc = docRef.set(data).then(() =&gt;  {
      res.send('Login Complete');
    })
    .catch(function(error) {
      console.error("Error adding document: ", error);
  });
  
  });
  
  
  
  const api1 = functions.https.onRequest(app);
  
  module.exports = {api1};
  </code></pre>
  
  <p>and here is the error I'm getting:</p>
  
  <pre><code>{ Error: 7 PERMISSION_DENIED: Missing or insufficient permissions.
  &gt;      at Object.callErrorFromStatus (/Users/mg8686./Desktop/mattsapp/mattsappfinal/backend/functions/node_modules/@grpc/grpc-js/build/src/call.js:30:26)
  &gt;      at Http2CallStream.call.on (/Users/mg8686./Desktop/mattsapp/mattsappfinal/backend/functions/node_modules/@grpc/grpc-js/build/src/client.js:96:33)
  &gt;      at Http2CallStream.emit (events.js:203:15)
  &gt;      at process.nextTick (/Users/mg8686./Desktop/mattsapp/mattsappfinal/backend/functions/node_modules/@grpc/grpc-js/build/src/call-stream.js:97:22)
  &gt;      at process._tickCallback (internal/process/next_tick.js:61:11)
  &gt;    code: 7,
  &gt;    details: 'Missing or insufficient permissions.',
  &gt;    metadata: Metadata { internalRepr: Map {}, options: {} } }
  
  
  </code></pre>
  
  <p>Can someone please take a look?  Thanks!</p>