Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
846 views
in Technique[技术] by (71.8m points)

create firebase database rule on key name

I need help on creating a firebase database rule. The use case is like this: the user (gamer) have 3 treasure boxes which can hold any treasure. User can purchase extra treasure box. So the tree structure in firebase database I came up is:

user
  |- settings
       |- max-t-box : 3
  |- boxes
       |- 1 : {} // a complicated data for the treasure or null
       |- 2 : {} // a complicated data for the treasure or null
       |- 3 : {} // a complicated data for the treasure or null

The rule on 'user/settings/max-t-box' is trivial: user read only and not allowed to write (it can only be modified by server side admin).

The rule under 'user/boxes' is supposed to be: the key of new data should be a number and it's value should be > 0 and <= 'user/setting/max-t-box' value.

According to firebase document, I can use $variable to capture path segment, however it does not provide enough api for me to check the path node name value.

So far the solution I come up is to write rules for path 'user/boxes/1', 'user/boxes/2' and 'user/boxes/3'. However this really looks stupid after user buys many boxes.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...