-1

How can I add roles to users to let them see specific views in my app?

EX: They have admin, it shows something | They have user, it is normal | They have unassigned, it shows a different page.

I need help with first, making the groups through firebase, but also implementing it into my app. I've searched far and wide but can't seem to find a tutorial for swiftUI. Anything appreciated.

Canyon
  • 45
  • 6
  • 1
    See [Rules](https://stackoverflow.com/questions/25641184/firebase-set-security-rules-depending-on-user-roles) and [This answer](https://stackoverflow.com/questions/69601139/how-can-i-get-only-the-users-with-roles-of-user) and really a lot of other answers [here](https://stackoverflow.com/search?q=%5Bfirebase%5Duser+roles) – Jay Dec 19 '21 at 14:01

1 Answers1

0

Use Firebase Security Rules, It allows you to allow or disallow access to your database, It's very easy, and part of Firebase:

As per Firebase:

Firebase Security Rules stand between your data and malicious users. You can write simple or complex rules that protect your app's data to the level of granularity that your specific app requires. Firebase Security Rules leverage extensible, flexible configuration languages to define what data your users can access for Realtime Database, Cloud Firestore, and Cloud Storage. Firebase Realtime Database Rules leverage JSON in rule definitions, while Cloud Firestore Security Rules and Firebase Security Rules for Cloud Storage leverage a unique language built to accommodate more complex rules-specific structures.

Here's an example for Firestore:

service <<name>> {
  // Specify your resource path.
  match <<path>> {
    // Allow the request if the following conditions are true.
    allow read, write: if <<condition>>
  }
}

... but for Realtime Database, It's JSON based:

{
  "rules": {
    "<<path>>": {
    // Allow the request if the condition for each method is true.
      ".read": <<condition>>,
      ".write": <<condition>>
    }
  }
}

Read more on https://firebase.google.com/docs/rules

excitedmicrobe
  • 2,338
  • 1
  • 14
  • 30
  • Is it possible to access the user database, and then make a list of emails that if they have that email, it sends them to a different page? EX: When they signup, it brings them to a screen that has a button to send a email. I've got that part down. I then check the database and add them to a user group if I recognize them. In Xcode, it accesses that, and if they are in that list, it shows a different view. This is the part I need help on. Is there an easier way to do it because I'm kind of confused. – Canyon Dec 18 '21 at 18:26
  • @Canyon, No need to get confused, what you're talking about is possible on front-end, not backend, You have an option to secure, and structure your data in the backend, how you work with this data on your app, is entirely dependent on your needs. – excitedmicrobe Dec 18 '21 at 18:34
  • Hmm. I'd rather it be backend through firebase because that makes everything so much easier. If you'd like I can make another post and give you the link, trying to explain what I need in more detail. – Canyon Dec 18 '21 at 18:49
  • possible with some python or nodejs knowledge using Functions, but that's not a way to go! – excitedmicrobe Dec 18 '21 at 18:50
  • ok so don't make a new post, but how do I implement it. When a user signs up, they are brought to a page with a button. That button sends an email to me, I've got that done already. What I need help with is, If I recognize the user, what's the easiest way to edit their 'permissions' so instead of going to the page with the button, it takes them to the normal app. FYI, I'm using firebase Auth to sign up and sign in. – Canyon Dec 18 '21 at 19:06
  • Can you dm me on discord? Rawa#7438 – excitedmicrobe Dec 18 '21 at 20:41
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240259/discussion-between-canyon-and-excitedmicrobe). – Canyon Dec 18 '21 at 20:44
  • I added you. countless#0001 – Canyon Dec 18 '21 at 21:27