# Can I force login to fail if the user lacks a property in app\_metadata?

**URL:** <https://community.auth0.com/t/can-i-force-login-to-fail-if-the-user-lacks-a-property-in-app-metadata/127319>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [February 14, 2024, 3:55pm UTC](https://community.auth0.com/t/can-i-force-login-to-fail-if-the-user-lacks-a-property-in-app-metadata/127319 "2024-02-14T15:55:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kkrp1](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@kkrp1](https://community.auth0.com/u/kkrp1)\
**Post date:** [February 14, 2024, 3:55pm UTC](https://community.auth0.com/t/can-i-force-login-to-fail-if-the-user-lacks-a-property-in-app-metadata/127319/1 "2024-02-14T15:55:48Z")

</div>

I’m using `app_metadata` to store users’ permissions within my app. What I’d like to do is force the login (using universal login) to fail if the user lacks a particular property within that meta data.

If this isn’t possible, I can just show an error screen after they login, but preferable would be that login fails.

Is this possible at all? Many thanks!

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 15, 2024, 12:04am UTC](https://community.auth0.com/t/can-i-force-login-to-fail-if-the-user-lacks-a-property-in-app-metadata/127319/3 "2024-02-15T00:04:57Z")

</div>

Hi @kkrp1,

Thanks for reaching out to the Auth0 Community!

Yes, it should be possible to deny a user access based on a property in their app\_metadata.

Here is an example you can use and adapt to your scenario:

```auto
/**
 * @param {Event} event - Details about the user and the context in which they are logging in.
 * @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
 */
exports.onExecutePostLogin = async (event, api) => {
  if (event.user.app_metadata.color !== 'blue') {
    api.access.deny(`Access to ${event.client.name} is not allowed.`);
  }
};

```

Please let me know if there’s anything else I can do to help.

Cheers,  
Rueben

---

<div class="post-metadata">

**Author:** ![kkrp1](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@kkrp1](https://community.auth0.com/u/kkrp1)\
**Post date:** [February 16, 2024, 12:17pm UTC](https://community.auth0.com/t/can-i-force-login-to-fail-if-the-user-lacks-a-property-in-app-metadata/127319/4 "2024-02-16T12:17:44Z")

</div>

Thanks Rueben! That looks perfect.

Additionally, you replied to another post of mine, whos existence I promptly forgot about, and by the time I remembered the post had auto-closed so I couldn’t reply to say thanks. Apologies!

---

<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 1, 2024, 12:18pm UTC](https://community.auth0.com/t/can-i-force-login-to-fail-if-the-user-lacks-a-property-in-app-metadata/127319/5 "2024-03-01T12:18:25Z")

</div>

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