Role based queries best practices

Updated for sake of context

Is there any documentation on how to do a role-based query? (I have no idea what it’s called)

Context: The user can have 2 roles, the coach & the client. So they can be both if they themselves want to use the platform on either side. Person looking for a coach while also being a coach.

Example, for one user they can have both roles and query themselves:

asClient {
  myself 
}

asCoach {
  myself 
}

I’m not sure if this is the best approach so if someone can recommend some best practices I’d be happy to hear them :smiley:

Thanks in advance!

Your elixir newbie

Hi @Morzaram,

As a elixir newbie colleague, I’d say you should probably address this concern to authorization layer (role based) and not the database itself.

You can assign roles to each identity and each role contain a different set of actions and then keep track of these permissions on a session (if you’re using Phoenix you can read this doc).

meant to set as reply (oops)

I think there’s some context here that I think is important that I forgot and doesn’t convey via example.

The user can have 2 roles, the coach & the client. So they can be both if they themselves want to use the platform.
Example, for one user they can have both roles and query themselves:

asClient {
  myself 
}

asCoach {
  myself 
}

Would this still be the best approach based off of what you’re recommending?

Thanks for taking the time :relaxed:

(updated original post to provide this context)

Would this still be the best approach based off of what you’re recommending?

I think so.
Role-based authorization doesn’t limit identities to possess only one role