# Limit hook to specific applications

**URL:** <https://community.auth0.com/t/limit-hook-to-specific-applications/33832>\
**Category:** Get Help\
**Tags:** rules, metadata, hooks\
**Created:** [November 15, 2019, 5:34pm UTC](https://community.auth0.com/t/limit-hook-to-specific-applications/33832 "2019-11-15T17:34:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wikoenig](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/wikoenig/32/16631_2.png) [@wikoenig](https://community.auth0.com/u/wikoenig)\
**Post date:** [November 15, 2019, 5:34pm UTC](https://community.auth0.com/t/limit-hook-to-specific-applications/33832/1 "2019-11-15T17:34:14Z")

</div>

I want to be able to limit the code that is run within a pre user registration hook to one specific client. I came across [this](http://community.auth0.com/t/are-hooks-applied-to-all-clients/9452) which seems to be a good solution, but I am having trouble getting it to work.

For the application that I want to use the logic within the hook, I added a key in application metadata named “isPreUserRegistrationHookActive” with a value of true. I created a rule with the following logic:

```
function (user, context, callback) {  
  context.clientMetadata = context.clientMetadata || {};
  
  if(context.clientMetadata.isPreUserRegistrationHookActive === true){
    context.connectionMetadata = context.connectionMetadata || {};
    context.connectionMetadata.isPreUserRegistrationHookActive = true;
  }
  
  callback(null, user, context);
}

```

When I test this rule and add that property to context.clientMetadata, I can see that the property is added to connectionMetadata in the rule output. Finally, I created the following conditional statement within my hook:

```
context.connectionMetadata = context.connectionMetadata || {}; 
if(context.connectionMetadata.isPreUserRegistrationHookActive === true){
// stuff
}

```

The logic within that if statement is not evaluated when I believe the rule should be setting the connectionMetadata property. If I use the runner and set the property myself, the logic is evaluated. What am I missing?

Is there a better way to do this? I suppose I could have the application set a user\_Metadata property to control the behavior, but I would rather not leave it up to the client (caller) to decide whether or not this logic is evaluated.

---

<div class="post-metadata">

**Author:** ![ashish](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ashish/32/7056_2.png) [@ashish](https://community.auth0.com/u/ashish)\
**Post date:** [November 19, 2019, 3:41am UTC](https://community.auth0.com/t/limit-hook-to-specific-applications/33832/2 "2019-11-19T03:41:20Z")

</div>

> [@wikoenig](#):
>
> isPreUserRegistrationHookActive

Is your hook pre-registration or post-registration? If it is former then Pre-registration hook will run _before_ any rules are executed. Rules are executed post successful authentication.

---

<div class="post-metadata">

**Author:** ![wikoenig](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/wikoenig/32/16631_2.png) [@wikoenig](https://community.auth0.com/u/wikoenig)\
**Post date:** [November 19, 2019, 3:42pm UTC](https://community.auth0.com/t/limit-hook-to-specific-applications/33832/3 "2019-11-19T15:42:31Z")

</div>

Ahhhh, that makes sense, thank you. Yes, my hook is pre-registration.

Is there any other way to access an application’s metadata within a hook? For now I am using the approach I mentioned at the end of my question (user\_Metadata).

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 8, 2024, 10:40am UTC](https://community.auth0.com/t/limit-hook-to-specific-applications/33832/4 "2024-01-08T10:40:43Z")

</div>

Hey there!

As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next [Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043) on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

[Learn more here!](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043)
