Closed hmellor closed 5 years ago
After a little experimentation, I think I've created all the Firebase pieces, and have launched it locally, and am able to login, but am still unable to place bids, it appears I need to configure the database. Is there a suggested rule that works well for it, and do I need to configure anything in the database to run it? I tried making the database publicly writeable, but still got an error about not being able to read property of undefined.
As for the instructions, a description of each of the pieces of Firebase that need to be turned on, and how to configure each of them would be helpful.
Can you tell me what you see in the developer console when you try to place a bid?
Some things to try in the meantime:
One thing I think I forgot to mention in the readme was that to initialise your auctions you must call resetAll()
(this simply calls resetStore()
and resetLive()
mentioned below) from a developer console. This creates all the auction documents in the FireStore database.
As for FireStore rules, these are the rules I have been using:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function isAdmin() {
return get(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == "insert long random secret string"
}
function isDocumentOverWrite() {
return request.resource.data.keys().hasOnly(resource.data.keys())
}
function isFieldOverWrite() {
return request.resource.data[request.resource.data.keys()[0]].keys().hasOnly(resource.data[request.resource.data.keys()[0]].keys())
}
function isLoggedIn() {
return exists(/databases/$(database)/documents/users/$(request.auth.uid))
}
match /users/{user} {
allow read, update, delete: if false;
allow create: if true;
}
match /auction-live/{items} {
allow get, list: if true;
allow create, delete: if isAdmin();
allow update: if isAdmin() || isLoggedIn(); //&& !isFieldOverWrite();
}
match /auction-store/{item} {
allow get, list: if false;
allow create, delete: if isAdmin();
allow update: if isAdmin() || isLoggedIn() && !isDocumentOverWrite();
}
}
}
These rules are to protect bids from being overwritten and to hide user names from non admin users (admin privilege is set manually in the user's document by setting the admin field to "insert long random secret string"
).
The flaw is that I could not get isFieldOverWrite()
to work in time so had to comment it out so that we could run the event. This means that while resetStore()
is only for admin users, resetLive()
is callable by anyone (Store is your backup copy of the auction that can only be read from inside the Firebase website, live is what is used to show the current state of the auction to your users).
Please let me know if there is anything else I can help you with :)
As per Commit 020dc40, proper documentation has now been added to README.md
I'm now up and running, thanks. Now to look at customizing, both generic ones for the project as well as custom ones for my use case.
Perfect, I'm glad it's all working well for you now. I have set up a separate issue for the broken generic rule I mentioned above.
After a little experimentation, I think I've created all the Firebase pieces, and have launched it locally, and am able to login, but am still unable to place bids, it appears I need to configure the database. Is there a suggested rule that works well for it, and do I need to configure anything in the database to run it? I tried making the database publicly writeable, but still got an error about not being able to read property of undefined.
As for the instructions, a description of each of the pieces of Firebase that need to be turned on, and how to configure each of them would be helpful.
I am having a similar issue. At the moment I am not able to place any bids. I noted that the auction-live collection is not created in the Firestore Database when I run resetAll(). The auction-store collection is created like it should. But the function resetLive() is throwing the following error:
caught (in promise) FirebaseError: No document to update: projects/<project-name>/databases/(default)/documents/auction-live/items
@BartokW could you share what helped you to get the project up-and-running? I know it's quite some time ago, but maybe you could still help me.
I really don't remember. All I remember was having to open the database up to writes from anywhere, and running a function, which was likely the resetAll() that you mentioned. Possibly there was something about making sure your user is setup as an admin, and that you're logged in as the admin user before running the function. Sorry I'm not more helpful.
Is your feature request related to a problem? Please describe. @BartokW has let me know that the Firebase instructions in the readme are relatively unclear for a first time Firebase user.
Describe the solution you'd like In order to simplify first time set up and website operation, I think that utilising the Wiki feature of GitHub will enable much of this to be self taught. Leading to a less repetitive issue feed.