Custom field security rules in Firebase

My Firebase security rules are structured like this:

"users": {
      "$uid": {
        // Allows write access only to the user whose uid matches the key ($uid)
        ".write": "auth !== null && auth.uid === $uid",

        // Grants read access to any user logged in with an email and password
        ".read": "auth !== null && auth.provider === 'password'"
      }
    },

Additionally, I have a unique userId stored in the users/$uid path. For example, my users/$uid structure looks like this:

users
   /$uid
       /email: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9cfc6c6e9cbc8db87cac6c4">[email protected]</a>
       /userId: "foobargayid123456"

I utilize this userId in other nodes, such as the profile_pictures node, to establish dependencies:

profile_pictures
   /userId
       /thumbnail: "datablabla"

Inquiry

How can I adjust the firebase security rules for the profile_pictures node so that only users with the id: users/$uid/userId have permission to .write to the profile_pictures/userId node?

Answer №1

This seems to be the solution you need.

{ 
  "permissions": {
    "profile_pics": {
      "$user_id": {
        ".write": "
          root.child('users').child(auth.uid).child('userId').val == $user_id"
      }
    }
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the proper way to invoke the bold feature in AngularJS?

I am looking to update the font properties (bold or italic) within a Textarea using AngularJS. Here is the code snippet for your review. Can anyone guide me on how to implement the bold property in my script? HTML: <div ng-app='myNoteApp' ng ...

Tips for utilizing session variables across two PHP backend files

I've been working on a project using AngularJs with a PHP backend. I successfully implemented the authentication process, but now I'm facing an issue with displaying the user data in another view after authentication. I've tried using sessio ...

Combining multiple events into one function using jQuery

I am searching for the opposite of what everyone else is seeking. I have an anonymous jQuery function that I want to keep as it is, but I need to attach multiple event handlers to it on different occasions (specifically two events). When the text inside ...

What is the process for creating separate files for modal controllers?

I have an Angular application with multiple modals, and I am using AngularUI to handle the modal directive. http://angular-ui.github.io/bootstrap/ Currently, my main controllers are all located in the app.js file as routes. $routeProvider.when '/da ...

Managing SQLite errors when using JavaScript and ExpressJS

I have developed a Backend route to retrieve games based on specific letters provided. Below are the two routes that I implemented: router.get("/public/gamelist/:letter", (req, res, next) => { var sql = "SELECT title FROM Games WHERE ti ...

Concern with Json Data Structure

How can I display data in the following layout: the datas that published today: data1, data2, the datas that published yesterday: data1, data2 If I receive the data in JSON format, what should the JSON structure look like to achieve this format? The HTM ...

Sorting data on-the-fly using an HTML Select drop-down menu

Looking for a way to dynamically sort data from a JavaScript object based on the user's selected option. If the user chooses ID, the data should be sorted by ID, and the same goes for Name. I've created a function and attached an onchange method ...

How can I extract text from .txt files to set as personalized response text?

Currently, I am working on creating a straightforward photo upload system. When a file is selected and the upload button is clicked, a loading gif appears along with a percentage uploaded. Once the upload is complete, an alert displays a message from an ar ...

Utilizing material-ui textfield involves a delay when the input is being focused

Is there a way to trigger inputRef.current.focus() without relying on setTimeout? It seems like the focus is not working as expected in React or MaterialUI. For a demonstration, visit: https://codesandbox.io/s/goofy-gareth-lkmq3?file=/src/App.js export de ...

Steps to resolve the Firebase alert stating "you're currently utilizing the development version of Firebase"

Despite following the standard advice I found on various sources to fix this warning in my Vue app, it still persists. This is how I am importing Firebase: import firebase from 'firebase/app'; import 'firebase/app'; import 'fireba ...

Redefining the type of an existing function in Typescript: A step-by-step guide

If you're looking for a solution where you can declare an existing function without defining an expression, check out this article: . Rather than creating a new function, the goal is to declare the existing function in a similar manner without using t ...

Building a dynamic button in React without relying on hardcoded properties

I'm currently working on creating a button in a React application, and here is the code I have so far: var React = require('react'); var buttonStyle = { margin: '10px 10px 10px 0' }; var Button = React.createClass({ render: ...

Error in AngularJS: Failed to retrieve data using $http.post()

One of my current challenges involves: Transferring text data from HTML form text boxes to the Controller using ng-model and ng-submit directives. Sending this data from the controller to a Service. The Issue at Hand: - I am facing difficulties accessi ...

The style of MUI Cards is not displaying properly

I've imported the Card component from MUI, but it seems to lack any styling. import * as React from "react"; import Box from "@mui/material/Box"; import Card from "@mui/material/Card"; import CardActions from "@mui/m ...

Can a dropdown menu be integrated into a text area?

Is it within the realm of possibility to achieve this? I believe it's worth exploring, so here goes my question. The Servlet API functions as a ticketing process or script that scans a form for specific form fields that match its predefined list of n ...

Unlocking the power of python with web2py by tapping into html form values

I'm working on a project using web2py and need to incorporate ajax/javascript with a form. Currently, when a user selects an option in the departure box, the arrival box appears. However, I'm unsure of how to filter the list of arrival options ba ...

Triggering the open() function within an Ajax request

Upon experimenting with the method open(), I discovered that it requires a URL file as an argument. For instance, I have two functions named generateGeometricShapes() and colorShapes(). I am contemplating whether I should create separate files for each fu ...

Can the MemoryRouter be successfully nested within the BrowserRouter in a React application?

I've been on a quest for some time now, trying to uncover whether it's feasible to utilize MemoryRouter solely for specific routes while maintaining the use of BrowserRouter in general. My goal is to navigate to a particular component without alt ...

Tips for maintaining the full width/height ratio of a child image when covering a fixed size container

I have a square container with dimensions of 300x300 and an <img src="" /> image inside. My goal is for the image to cover the entire container while maintaining its width/height ratio. If the image's width is smaller than its height ...

When trying to access Ajax fetched data within a VueJS `router-view`, the `$root` object returns undefined only when navigating directly to

As I familiarize myself with vuejs, I decided to challenge myself by creating a webpage similar to an eshop for practice purposes. My approach involves fetching all the necessary data in a single api call to ensure easy access from all my router-views for ...