I have a client-side web app using Firestore and Cloud Functions.
I would like to set up rules such that if a user has a secret URL for a document that user is able to write to it, without need any other kind of login or authentication. Something like (pseudo-code, I just made up request.params.secret_token
):
service cloud.firestore {
match /databases/{database}/documents {
match /cities/{city} {
allow read, write: if resource.data.secret_token == request.params.secret_token;
}
}
}
I'm confused by the various authentication options available and can't quite reason through the best way forward.
Potential options that feel close:
Firebase gives you complete control over authentication by allowing you to authenticate users or devices using secure JSON Web Tokens (JWTs). You generate these tokens on your server, pass them back to a client device, and then use them to authenticate via the signInWithCustomToken() method.
In the present era, user authentication is one of the most important requirements for Android apps. It is essential to authenticate users, and it is much harder if we have to write all this code on our own. This is done very easily with the help of Firebase.
You can use Firebase Authentication to sign in a user by sending an SMS message to the user's phone. The user signs in using a one-time code contained in the SMS message.
if a user has a secret URL for a document that user is able to write to it, without need any other kind of login or authentication.
Simply set your database rules to allow anyone to read and/or write the data at the path specified in the JavaScript on/in that particular webpage. Maybe simply put the database read or write in a <script>
tag after your firebase <script>
tag right in that page.
However, like you said, anyone that visits that page/URL is gonna be able to read and/or write whatever data is in that particular node, or field, or document.
Edit the firestore.rules file like so to enable read write for anyone/all. See Documentation.
service cloud.firestore {
match /databases/{database}/documents {
match /<some_path>/ {
allow read, write;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With