sanch
sanch

Reputation: 716

How should I model my data in Firebase?

I am currently developing (my first ever) iOS app using firebase and testing with a small group of users and everything is going fine (because I am hard-coding the org code into the ref builder). The app is structured around having autonomous organizations with its own users hidden from other organizations. The problem that I am running into is how I structure my model so that it is possible to access and it is efficient when it starts to add new organizations and users.

specific problem: Org names are dynamically created, so my login pattern needs to be able authenticate the user in Firebase, then retrieve the user's data stored in the database under their specific org code. I can't figure out how to save the org code for login each time the user opens the app so they don't need to type it in. Technically I could pull down the whole the database to find it but that's the worst possible solution. Would I maybe need to use Core Data?

-_admin
    -org1
        -name
        -availble_licenses
        -used_licenses
    -org2
    -org3
    ...
-org1
    -users
        -$uid
           -name
           -uid
           -email
        -$uid
        -$uid
        ...
-org2
...

Upvotes: 0

Views: 48

Answers (1)

Arrabidas92
Arrabidas92

Reputation: 1153

My answer is based on this assumption

I can't figure out how to save the org code for login each time the user opens the app so they don't need to type it in.

For this, you don't need Core data but UserDefaults. Core data it's for a huge set of data. On the contrary, UserDefaults, it's useful to store tiny data. It's like user preferences :

The UserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an app to customize its behavior to match a user’s preferences.

So you can use it to store the org code for a specific user. Here is a tutorial on how to use UserDefaults : UserDefaults

Upvotes: 1

Related Questions