Git Product home page Git Product logo

Comments (4)

linusmartensson avatar linusmartensson commented on May 21, 2024

functions/db/admins/onWrite.f.js:

import { database } from 'firebase-functions'
import admin from 'firebase-admin'

exports = module.exports = database
    .ref('/admins/{userUid}')
    .onWrite((change, context) => {
        const userUid = context.params.userUid
        if(change.before.exists()){
            if(!change.after.exists())
                return admin.firestore().collection('admins').doc(userUid).delete();
        } else if(change.after.exists())
            return admin.firestore().collection('admins').doc(userUid).set({});
        return null;
    })                     

functions/db/userGrants/onWrite.f.js:

import { database } from 'firebase-functions'
import admin from 'firebase-admin'

exports = module.exports = database
  .ref('/user_grants/{userUid}/{grantName}')
    .onWrite((eventSnapshot, context) => {
        const userUid = context.params.userUid
        const grantName = context.params.grantName
        let prm = {}
        if (eventSnapshot.after.val()) {
            prm[grantName] = true;
        } else {
            prm[grantName] = false;
        }
        return admin.firestore().collection('user_grants').doc(userUid).set(prm, {merge:true});
  })

I added the above for now to duplicate privilege changes from the RDB into Firestore. It seems to be working in case anyone else is stumped by the issue.
Would appreciate an official word on how this should be handled! :)

from react-most-wanted.

TarikHuber avatar TarikHuber commented on May 21, 2024

Hi @linusmartensson there should be a sync from RTD to Firestore. We do it the same in our company.

from react-most-wanted.

TarikHuber avatar TarikHuber commented on May 21, 2024

omg it seems I frogot to put the sync in the demo -.-

from react-most-wanted.

TarikHuber avatar TarikHuber commented on May 21, 2024

Updated the project to have integrated sync of admins and grants to firestore. Also to sync admins and grants with "storage" in it's name to the custom auth tokens. Because you can't access RTD and Firestore on the storage rules the only solution is to do it over those custom tokens. Sync of all of them would not fit so we sync only those witch have "storage" in they're name.

from react-most-wanted.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.