# Setting user\_metadata in Action does not work if login is denied

**URL:** <https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446>\
**Category:** Get Help\
**Tags:** login\
**Created:** [November 19, 2021, 10:33am UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446 "2021-11-19T10:33:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![alberto.ornaghi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alberto.ornaghi/32/33125_2.png) [@alberto.ornaghi](https://community.auth0.com/u/alberto.ornaghi)\
**Post date:** [November 19, 2021, 10:33am UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/1 "2021-11-19T10:33:55Z")

</div>

Hello,

I’m trying to creare a post-login action that performs this:

```auto
if (event.user.user_metadata.approved !== true) {
    api.user.setUserMetadata("pending_approval", true);
    api.access.deny("You need to be approved before being able to log in...");
}

```

I’ve noticed that the “pending\_approval” field is not set if I deny the access to the user. if I remove the last line of code, it works as expected.

the doc says:

> " Mark the current login attempt as denied. This will prevent the end-user from completing the login flow. This will _NOT_ cancel other user-related side-effects (such as metadata changes) requested by this Action. The login flow will immediately stop following the completion of this action and no further Actions will be executed."

so it should work as expected…

what’s wrong with my code?

thank you.

---

<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:** [November 19, 2021, 8:43pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/3 "2021-11-19T20:43:53Z")

</div>

Hi @alberto.ornaghi,

Welcome to the Auth0 Community!

> [@alberto.ornaghi](#):
>
> what’s wrong with my code?

There is nothing logically wrong with your code. However, after testing this for myself, I found the same observations. Specifically, the user\_metadata is never set before being denied access.

And as you hinted, our docs indicate that the metadata should be able to change as long as the `api.access.deny()` is called afterward.

Since I have confirmed your findings, I will reach out to our Engineering teams regarding this bug and have them resolve the issue.

Once there is new information, I will follow up with you with the updates.

Thank you.

---

<div class="post-metadata">

**Author:** ![alberto.ornaghi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alberto.ornaghi/32/33125_2.png) [@alberto.ornaghi](https://community.auth0.com/u/alberto.ornaghi)\
**Post date:** [December 6, 2021, 10:36am UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/4 "2021-12-06T10:36:35Z")

</div>

any update on the issue? do you have an ETA for the fix?

thank you

---

<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:** [December 6, 2021, 5:02pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/6 "2021-12-06T17:02:06Z")

</div>

Hi @alberto.ornaghi,

Thank you for your reply.

I have reached out to our Engineers on this and waiting for a response.

I’d like to also add that we are currently on a Code Freeze, which we expect to remove after the new year, sometime in early January 2022.

With that said, I anticipate this issue to be part of the list of bugs fixed and will be reflected in the product once the code freeze has been lifted.

Thank you.

---

<div class="post-metadata">

**Author:** ![andres](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andres/32/14372_2.png) [@andres](https://community.auth0.com/u/andres)\
**Post date:** [January 7, 2022, 5:56pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/7 "2022-01-07T17:56:11Z")

</div>

Hi! We bumped into a similar scenario when porting our Rules to Actions, so a fix would be greatly appreciated here too. 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:** [January 7, 2022, 6:12pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/8 "2022-01-07T18:12:18Z")

</div>

Hi @andres,

Thanks for reporting this issue as well.

Once our code freeze has been lifted, these issues will be resolved.

I’ll follow up when that happens.

Thanks!

---

<div class="post-metadata">

**Author:** ![jack.macdonald](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jack.macdonald/32/12764_2.png) [@jack.macdonald](https://community.auth0.com/u/jack.macdonald)\
**Post date:** [April 7, 2022, 2:49pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/9 "2022-04-07T14:49:39Z")

</div>

@rueben.tiow it’s now April and this bug is still present, we cannot write to app\_metadata or user\_metadata when api.access.deny() is called.  
When will this bug be resolved please? We need a date for this bugfix being released

---

<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:** [April 14, 2022, 12:49am UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/11 "2022-04-14T00:49:09Z")

</div>

Hi @jack.macdonald,

Thank you for your response.

I have clarified with our Engineering Teams that this issue has been resolved and you should be able to set user\_metadata before denying them access.

Moreover, I have not seen any further topics regarding this issue, could you please check again to see if you can set the user\_metadata before denying them access?

Thank you.

---

<div class="post-metadata">

**Author:** ![jack.macdonald](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jack.macdonald/32/12764_2.png) [@jack.macdonald](https://community.auth0.com/u/jack.macdonald)\
**Post date:** [April 14, 2022, 8:26am UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/12 "2022-04-14T08:26:51Z")

</div>

I can confirm this is still not working, for user\_metadata and app\_metadata. I am tracking this in support ticket 00714794.

---

<div class="post-metadata">

**Author:** ![ivan.mikhalitsyn](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ivan.mikhalitsyn/32/34158_2.png) [@ivan.mikhalitsyn](https://community.auth0.com/u/ivan.mikhalitsyn)\
**Post date:** [April 29, 2022, 1:06pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/14 "2022-04-29T13:06:47Z")

</div>

Hi, same here. I have a custom parameter passed in auth0-react loginWithRedirect() function. And I have Auth0 post-login action configured (with debug printouts):

```auto
exports.onExecutePostLogin = async (event, api) => {
  console.log(event.request.query);
  console.log(event.request.query.intendedPrice);
  console.log(event.stats.logins_count);
  console.log(event.user.email_verified);

  if (event.stats.logins_count === 1) {
    console.log('First login');
    if (event.request.query.intendedPrice) {
        console.log(`Setting intended price ${event.request.query.intendedPrice}`);
        api.user.setUserMetadata("intendedPrice", event.request.query.intendedPrice);
        api.user.setAppMetadata("intendedPrice", event.request.query.intendedPrice);
    }
  }
 //force email verification
  if (!event.user.email_verified) {
    api.access.deny("Verification email is sent. Please verify your email address to continue");
    return;
  }

... some other stuff for verified email login flow
}

```

I see expected printouts about setting the intendedPrice metadata field in the logs, but actual user metadata does not gets updated.

It there any progress with the fix mentioned above or some another way to pass parameters to the user’s metadata to use it once he or she verifies the email?

My use case is to allow someone to sign up to pre-selected subscription, but I also need to force them to verify the email first to avoid signing up with dead or mistyped email. Desired flow:

1. user selects the subscription plan
2. clicks ‘sign up’ and performs sign up procedure
3. goes to mailbox and clicks the verification link and gets redirected back to my application
4. my application checks the subscription plan id from the metadata and handles it appropriately

Thanks in advance

---

<div class="post-metadata">

**Author:** ![jack.macdonald](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jack.macdonald/32/12764_2.png) [@jack.macdonald](https://community.auth0.com/u/jack.macdonald)\
**Post date:** [April 29, 2022, 1:32pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/15 "2022-04-29T13:32:40Z")

</div>

We’ve had to use the auth0 package within the action, and use the ManagementClient on that to set users app metadata instead. Similar to [Is there a way to access user management api from a post-password-change action? - #2 by thameera](https://community.auth0.com/t/is-there-a-way-to-access-user-management-api-from-a-post-password-change-action/66823/2)

---

<div class="post-metadata">

**Author:** ![ivan.mikhalitsyn](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ivan.mikhalitsyn/32/34158_2.png) [@ivan.mikhalitsyn](https://community.auth0.com/u/ivan.mikhalitsyn)\
**Post date:** [April 29, 2022, 1:59pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/16 "2022-04-29T13:59:37Z")

</div>

Thanx Jack, I was thinking about the same approach as a possible workaround.

Although, I really hope that Auth0 team will fix this issue anyway. @rueben.tiow could you please inform us when this happens.

---

<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:** [May 2, 2022, 4:23pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/17 "2022-05-02T16:23:06Z")

</div>

Hi @ivan.mikhalitsyn and @jack.macdonald,

Thank you for your responses.

I have gotten clarification that this issue is still in our backlog to be fixed.

As soon as our Engineers resolve the issue, I will follow up on this thread.

Thank you.

---

<div class="post-metadata">

**Author:** ![shannon.paige](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shannon.paige/32/13031_2.png) [@shannon.paige](https://community.auth0.com/u/shannon.paige)\
**Post date:** [June 8, 2022, 4:33pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/18 "2022-06-08T16:33:03Z")

</div>

Just adding a comment that we are also very interested in this being fixed. Has there been any update?

---

<div class="post-metadata">

**Author:** ![rrmakatu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rrmakatu/32/33927_2.png) [@rrmakatu](https://community.auth0.com/u/rrmakatu)\
**Post date:** [June 20, 2022, 9:59pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/19 "2022-06-20T21:59:54Z")

</div>

Hi,

When will this be resolved ? Also facing same issue.

---

<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:** [July 15, 2022, 6:47pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/20 "2022-07-15T18:47:29Z")

</div>

Hi @rrmakatu,

Thank you for sharing that you are encountering the same issues.

After checking with our Engineering teams, they have confirmed that this issue has been resolved.

Moreover, I have tested this myself and confirm that updating the user\_metadata persists through subsequent Actions.

Please reach out if you have any further questions or concerns.

Thank you.

---

<div class="post-metadata">

**Author:** ![shannon.paige](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shannon.paige/32/13031_2.png) [@shannon.paige](https://community.auth0.com/u/shannon.paige)\
**Post date:** [August 9, 2022, 5:08pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/21 "2022-08-09T17:08:42Z")

</div>

Hi @rueben.tiow  
This still isn’t working for us.

For example I have the following code

```auto
api.user.setUserMetadata("failed_login", "deactivated customer");
api.access.deny(`Oops, something went wrong! #7833`);

```

but when I look up logs for users that have failed login in this way, I don’t see the metadata.

---

<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:** [August 16, 2022, 4:15pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/22 "2022-08-16T16:15:02Z")

</div>

Hi @shannon.paige and @rrmakatu,

Thank you for your replies.

Previously, I had seen this issue resolve and work synchronously. However, after some tests, I managed to reproduce the same issue again.

I will investigate this issue with our Engineers and follow up once I have more information.

Thank you.

---

<div class="post-metadata">

**Author:** ![dmitry.gerasimenko](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dmitry.gerasimenko/32/41916_2.png) [@dmitry.gerasimenko](https://community.auth0.com/u/dmitry.gerasimenko)\
**Post date:** [December 13, 2022, 6:44pm UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/23 "2022-12-13T18:44:52Z")

</div>

Hi @rueben.tiow. It’s been a year now, but the bug is still present. Are there any updates?

---

<div class="post-metadata">

**Author:** ![cperx](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cperx/32/42279_2.png) [@cperx](https://community.auth0.com/u/cperx)\
**Post date:** [January 4, 2023, 7:47am UTC](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446/24 "2023-01-04T07:47:12Z")

</div>

We are also having this issue. any timeline on a fix?

[Next page](https://community.auth0.com/t/setting-user-metadata-in-action-does-not-work-if-login-is-denied/73446.md?page=2)
