这是indexloc提供的服务,不要输入任何密码
Skip to content

PERMISSION_DENIED in firebase emulator using Google Auth provider #3258

@jean-smaug

Description

@jean-smaug

[REQUIRED] Environment info

firebase-tools: 9.8.0

Platform: MacOS Catalina 10.15.6

[REQUIRED] Test case

I'm trying to insert data in firebase firestore emulator.
I'm using two emulators : firestore and auth.
User is logged using Google auth provider. So I created a mock user that have Google as auth provider.
But I can't insert data with firestore auth rules.

// firebase web SDK config
import firebase from "firebase/app";

import "firebase/analytics";
import "firebase/auth";
import "firebase/firestore";
import { isMock } from "../utils/environement";

const firebaseConfig = {
  apiKey: "...",
  authDomain: "...",
  projectId: "...",
  storageBucket: "...",
  messagingSenderId: "...",
  appId: "...",
  measurementId: "...",
};

if (!firebase.apps.length) {
  firebase.initializeApp(firebaseConfig);
}

if (isMock) {
  firebase.auth().useEmulator("http://localhost:9099");

  firebase.firestore().settings({
    experimentalForceLongPolling: true,
  });
  firebase.firestore.setLogLevel("debug");
  firebase.firestore().useEmulator("0.0.0.0", 8080);
}

export default firebase;
// firestore.rules

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}
// firebase.json
{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "storage": {
    "rules": "storage.rules"
  },
  "emulators": {
    "auth": {
      "port": 9099
    },
    "firestore": {
      "port": 8080
    },
    "ui": {
      "enabled": true
    }
  }
}

[REQUIRED] Steps to reproduce

My app is a next.js app.
So next start and firebase emulators:start.

In my code I try to do the following

const MyComponent = () => {
  React.useEffect(() => {
    firebase.firestore().collection("users").add({ some: "data" })
  }, [])
  
  return (...)
}

[REQUIRED] Expected behavior

I'm expecting to have my data inserted -

[REQUIRED] Actual behavior

An error is sent

Here are the logs displayed in console

[2021-04-04T15:50:19.078Z]  @firebase/firestore: Firestore (8.3.2): FirestoreClient Received user= hJbX2oOFLzuYcqMHdVXbdAMp1dIO
index.esm.js?abfd:106 [2021-04-04T15:50:19.081Z]  @firebase/firestore: Firestore (8.3.2): FirestoreClient Using default OnlineComponentProvider
index.esm.js?abfd:106 [2021-04-04T15:50:19.081Z]  @firebase/firestore: Firestore (8.3.2): FirestoreClient Using default OfflineComponentProvider
index.esm.js?abfd:106 [2021-04-04T15:50:19.081Z]  @firebase/firestore: Firestore (8.3.2): FirestoreClient Initializing OfflineComponentProvider
index.esm.js?abfd:106 [2021-04-04T15:50:19.083Z]  @firebase/firestore: Firestore (8.3.2): FirestoreClient Initializing OnlineComponentProvider
index.esm.js?abfd:106 [2021-04-04T15:50:19.085Z]  @firebase/firestore: Firestore (8.3.2): MemoryPersistence Starting transaction: Locally write mutations
index.esm.js?abfd:106 [2021-04-04T15:50:19.088Z]  @firebase/firestore: Firestore (8.3.2): MemoryPersistence Starting transaction: Get next mutation batch
index.esm.js?abfd:106 [2021-04-04T15:50:19.089Z]  @firebase/firestore: Firestore (8.3.2): MemoryPersistence Starting transaction: Get next mutation batch
index.esm.js?abfd:106 [2021-04-04T15:50:19.090Z]  @firebase/firestore: Firestore (8.3.2): Connection Creating WebChannel: http://0.0.0.0:8080/google.firestore.v1.Firestore/Write/channel {"httpSessionIdParam":"gsessionid","initMessageHeaders":{"X-Goog-Api-Client":"gl-js/ fire/8.3.2","X-Firebase-GMPID":"1:748589150774:web:46b259f11b4927aa971e97","Content-Type":"text/plain","Authorization":"Bearer eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJuYW1lIjoiT3R0ZXIgT2xpdmUiLCJlbWFpbCI6Im90dGVyLm9saXZlLjY0NEBleGFtcGxlLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdXRoX3RpbWUiOjE2MTc1NTAyOTcsInVzZXJfaWQiOiJoSmJYMm9PRkx6dVljcU1IZFZYYmRBTXAxZElPIiwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJvdHRlci5vbGl2ZS42NDRAZXhhbXBsZS5jb20iXSwiZ29vZ2xlLmNvbSI6WyI4MjcyNzkyNzEwOTU2MjAwNTUwMTEwNTM4NzY2NzgyOTU5NDU2NTY0Il19LCJzaWduX2luX3Byb3ZpZGVyIjoiZ29vZ2xlLmNvbSJ9LCJpYXQiOjE2MTc1NTAyOTcsImV4cCI6MTYxNzU1Mzg5NywiYXVkIjoiZmlyZWRldi05YmQxYyIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9maXJlZGV2LTliZDFjIiwic3ViIjoiaEpiWDJvT0ZMenVZY3FNSGRWWGJkQU1wMWRJTyJ9."},"messageUrlParams":{"database":"projects/.../databases/(default)"},"sendRawJson":true,"supportsCrossDomainXhr":true,"internalChannelParams":{"forwardChannelRequestTimeoutMs":600000},"forceLongPolling":true,"detectBufferingProxy":false,"httpHeadersOverwriteParam":"$httpHeaders"}
index.esm.js?abfd:106 [2021-04-04T15:50:19.091Z]  @firebase/firestore: Firestore (8.3.2): RemoteStore RemoteStore received new credentials
index.esm.js?abfd:106 [2021-04-04T15:50:19.092Z]  @firebase/firestore: Firestore (8.3.2): RemoteStore Stopping write stream with 1 pending writes
index.esm.js?abfd:106 [2021-04-04T15:50:19.093Z]  @firebase/firestore: Firestore (8.3.2): MemoryPersistence Starting transaction: Get next mutation batch
index.esm.js?abfd:106 [2021-04-04T15:50:19.093Z]  @firebase/firestore: Firestore (8.3.2): MemoryPersistence Starting transaction: Get next mutation batch
index.esm.js?abfd:106 [2021-04-04T15:50:19.094Z]  @firebase/firestore: Firestore (8.3.2): Connection Creating WebChannel: http://0.0.0.0:8080/google.firestore.v1.Firestore/Write/channel {"httpSessionIdParam":"gsessionid","initMessageHeaders":{"X-Goog-Api-Client":"gl-js/ fire/8.3.2","X-Firebase-GMPID":"1:748589150774:web:46b259f11b4927aa971e97","Content-Type":"text/plain","Authorization":"Bearer eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJuYW1lIjoiT3R0ZXIgT2xpdmUiLCJlbWFpbCI6Im90dGVyLm9saXZlLjY0NEBleGFtcGxlLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdXRoX3RpbWUiOjE2MTc1NTAyOTcsInVzZXJfaWQiOiJoSmJYMm9PRkx6dVljcU1IZFZYYmRBTXAxZElPIiwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJvdHRlci5vbGl2ZS42NDRAZXhhbXBsZS5jb20iXSwiZ29vZ2xlLmNvbSI6WyI4MjcyNzkyNzEwOTU2MjAwNTUwMTEwNTM4NzY2NzgyOTU5NDU2NTY0Il19LCJzaWduX2luX3Byb3ZpZGVyIjoiZ29vZ2xlLmNvbSJ9LCJpYXQiOjE2MTc1NTAyOTcsImV4cCI6MTYxNzU1Mzg5NywiYXVkIjoiZmlyZWRldi05YmQxYyIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9maXJlZGV2LTliZDFjIiwic3ViIjoiaEpiWDJvT0ZMenVZY3FNSGRWWGJkQU1wMWRJTyJ9."},"messageUrlParams":{"database":"projects/.../databases/(default)"},"sendRawJson":true,"supportsCrossDomainXhr":true,"internalChannelParams":{"forwardChannelRequestTimeoutMs":600000},"forceLongPolling":true,"detectBufferingProxy":false,"httpHeadersOverwriteParam":"$httpHeaders"}
index.esm.js?abfd:106 [2021-04-04T15:50:19.096Z]  @firebase/firestore: Firestore (8.3.2): PersistentStream stream callback skipped by getCloseGuardedDispatcher.
index.esm.js?abfd:106 [2021-04-04T15:50:19.097Z]  @firebase/firestore: Firestore (8.3.2): Connection Opening WebChannel transport.
index.esm.js?abfd:106 [2021-04-04T15:50:19.098Z]  @firebase/firestore: Firestore (8.3.2): Connection WebChannel sending: {"database":"projects/.../databases/(default)"}
index.esm.js?abfd:106 [2021-04-04T15:50:19.109Z]  @firebase/firestore: Firestore (8.3.2): Connection WebChannel transport opened.
index.esm.js?abfd:106 [2021-04-04T15:50:19.115Z]  @firebase/firestore: Firestore (8.3.2): Connection WebChannel received: {"streamId":"12","streamToken":"MA=="}
index.esm.js?abfd:106 [2021-04-04T15:50:19.116Z]  @firebase/firestore: Firestore (8.3.2): Connection WebChannel sending: {"streamToken":"MA==","writes":[{"update":{"name":"projects/.../databases/(default)/documents/polls/hS8rhYb6qPEwsK500ONQ/votes/hJbX2oOFLzuYcqMHdVXbdAMp1dIO","fields":{"ranking":{"arrayValue":{"values":[{"mapValue":{"fields":{"id":{"stringValue":"answer-4"},"rank":{"integerValue":"1"},"value":{"stringValue":"ezg"}}}},{"mapValue":{"fields":{"id":{"stringValue":"answer-3"},"rank":{"integerValue":"2"},"value":{"stringValue":"ez"}}}},{"mapValue":{"fields":{"id":{"stringValue":"answer-2"},"rank":{"integerValue":"3"},"value":{"stringValue":"fze"}}}},{"mapValue":{"fields":{"id":{"stringValue":"answer-1"},"rank":{"integerValue":"4"},"value":{"stringValue":"fzefez"}}}},{"mapValue":{"fields":{"id":{"stringValue":"answer-0"},"rank":{"integerValue":"5"},"value":{"stringValue":"zefzef"}}}}]}},"date":{"timestampValue":"2021-04-04T15:50:19.075000000Z"}}}}]}
index.esm.js?abfd:106 [2021-04-04T15:50:19.131Z]  @firebase/firestore: Firestore (8.3.2): Connection WebChannel received error: {"message":"PERMISSION_DENIED: \nfalse for 'create' @ L5","status":"PERMISSION_DENIED"}
index.esm.js?abfd:106 [2021-04-04T15:50:19.133Z]  @firebase/firestore: Firestore (8.3.2): PersistentStream close with error: FirebaseError: [code=permission-denied]: PERMISSION_DENIED: 
false for 'create' @ L5
index.esm.js?abfd:106 [2021-04-04T15:50:19.134Z]  @firebase/firestore: Firestore (8.3.2): MemoryPersistence Starting transaction: Reject batch
index.esm.js?abfd:106 [2021-04-04T15:50:19.171Z]  @firebase/firestore: Firestore (8.3.2): MemoryPersistence Starting transaction: Get next mutation batch

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions