firebase-tools: PERMISSION_DENIED in firebase emulator using Google Auth provider
[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
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 27 (8 by maintainers)
Hi! How is this still a thing?
same issue here as well with “firebase”: “^7.0 || ^8.0”,
@akauppi @markgoho @kroikie we found the problem and have a fix. It’s being fixed in two places:
Right now neither fix has been released but when the next JS SDK and Emulator release go out either fix should be sufficient to stop this issue from happening.
Right now the only workaround is to downgrade your JS SDK to 8.3.1 or lower, as mentioned.
I fixed my issue this way:
curl -sL firebase.tools | uninstall=true bash
~/.cache/firebase
.The error disappeared 😄
This should be fixed in Firebase CLI v9.9.0.
For me at least, it only happens with v8.3.2 of the Firebase js sdk. 8.3.1 works fine against current tools, so it may be an sdk regression.
@NayamAmarshe this is actually the correct answer and you win one internet. Also note that you may need to upgrade Java after doing this.
The reason it works is that
firebase-tools
caches the emulator binaries in the directory and upgradingfirebase-tools
doesn’t automatically blow away the old emulator binaries.I’m assuming it still hasn’t been merged since I’m having this problem on a fresh project.
One question though - how do I downgrade the JS SDK to 8.3.1 or lower? Is it a dependency of the global
firebase-tools
or is a dependency in myfunctions
folder?update: stupid me, it was the angular client. Downgraded, works great!
Hi all, we’ve located the problem in Firestore Emulator and we are working on a fix. In the meantime, downgrading to Firestore JS SDK v8.3.1 is a possible workaround.
I’m also having the same issue, just linking another issue here https://github.com/firebase/firebase-js-sdk/issues/4721
@yuchenshi we are continuing to get reports of this issue, from @kroikie as well as here: https://github.com/firebase/firebase-js-sdk/issues/4795#issuecomment-821796615
Is there some other path we didn’t consider?
I’m still seeing this on
9.9.0
of the CLI with8.4.1
of the SDK. Downgrading the SDK to8.3.1
still works as a workaround for me.Thanks for all the info everyone! Sounds like an issue with the JS SDK 8.3.2 release … we’re going to dig into it.