# Connection based roles for multiple applications

**URL:** <https://community.auth0.com/t/connection-based-roles-for-multiple-applications/57760>\
**Category:** Get Help\
**Created:** [February 12, 2021, 2:26am UTC](https://community.auth0.com/t/connection-based-roles-for-multiple-applications/57760 "2021-02-12T02:26:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dstringers](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dstringers/32/13316_2.png) [@dstringers](https://community.auth0.com/u/dstringers)\
**Post date:** [February 12, 2021, 2:26am UTC](https://community.auth0.com/t/connection-based-roles-for-multiple-applications/57760/1 "2021-02-12T02:26:52Z")

</div>

Hi there. I am trying to configure multiple different applications to use one database, and for each user, be able to set access to the applications). I am trying to understand the finer points of the Auth0 interface, and I have come up with an idea for how I can implement this, but I wanted to see if anyone could give some feedback.

1. Give each user in the application one or more roles (which corresponds to the applications they have access to) in the user metadata.
2. Create a **Rule** which checks the users role upon authentication.
3. Somehow apply one rule for each application.

Is it possible to apply a rule to a single application, or do I need to use a global rule to check the application that the request is coming from (via the **context** variable?)

Thanks!

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [February 16, 2021, 12:58pm UTC](https://community.auth0.com/t/connection-based-roles-for-multiple-applications/57760/3 "2021-02-16T12:58:31Z")

</div>

Hi @dstringers,

Welcome to the Community!

> [@dstringers](#):
>
> 1. Give each user in the application one or more roles (which corresponds to the applications they have access to) in the user metadata.
> 2. Create a **Rule** which checks the users role upon authentication.
> 3. Somehow apply one rule for each application.

I think this approach makes sense!

> [@dstringers](#):
>
> Is it possible to apply a rule to a single application, or do I need to use a global rule to check the application that the request is coming from (via the **context** variable?)

Unfortunately, rules cannot be applied to individual applications, so you will need to add a check on the context object’s `context.clientName` property like so:

```auto
function ruleForSpecificApp(user, context, callback) {
  // only run rule for NameOfTheApp
  // bypass this rule for all other apps
  if(context.clientName !== 'NameOfTheApp'){
    return callback(null, user, context);
  }
 
  // add rule logic here

  return callback(null, user, context);
}

```

Here is an FAQ for applying default roles which may be helpful for your implementation:

- [How do I add a default role to a new user on first login? - #2](https://community.auth0.com/t/how-do-i-add-a-default-role-to-a-new-user-on-first-login/25857/2)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 3, 2021, 12:59pm UTC](https://community.auth0.com/t/connection-based-roles-for-multiple-applications/57760/4 "2021-03-03T12:59:05Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
