# Post login trigger not working as expected

**URL:** <https://community.auth0.com/t/post-login-trigger-not-working-as-expected/168128>\
**Category:** Get Help\
**Tags:** user-import-export, user-management\
**Created:** [January 10, 2025, 9:15am UTC](https://community.auth0.com/t/post-login-trigger-not-working-as-expected/168128 "2025-01-10T09:15:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![purva.jantikar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/purva.jantikar/32/61024_2.png) [@purva.jantikar](https://community.auth0.com/u/purva.jantikar)\
**Post date:** [January 10, 2025, 9:15am UTC](https://community.auth0.com/t/post-login-trigger-not-working-as-expected/168128/1 "2025-01-10T09:15:08Z")

</div>

I am migrating data from keycloak to auth0, As per auth0 email format is not allowed in username field. Due to this i have imported **username** as login\_identifier in **app\_metadata**  
Refer to this below

```auto
[
    {
        "user_id" : "79b72656-7a50-4214-985e-fa537efe85e0",
        "given_name": "test",
        "family_name": "user",
        "email": "test1@gmail.com",
        "email_verified": false,
        "custom_password_hash": {
            "algorithm": "pbkdf2",
            "hash": {
                "value": "$pbkdf2-sha256$i=27500,l=64$5TXiLHDApo9xDKVk1Qsarw$D4VVb7Uo0QIo/4vulomwT43Sn99hMf3d5LaB8Ufi3BXPkZrWF7rcAdN+u3miltoYvkJIx2//roiDpvkdI+fU3A"
            }
         },
         "app_metadata": {
            "login_identifier": "test123@gmail.com"
          }
    }
]

```

I am trying to ensure that this login\_identifier is used for login instead of email.

I have written a custom action : VALIDATE\_USERNAME

```auto
exports.onExecutePostLogin = async (event, api) => {

// Extract the entered username (email-like) from the request
  const enteredUsername = event.request.body.email;

  // Extract the stored username from app_metadata
  const storedUsername = event.user.app_metadata?.login_identifier;

  // Check if entered username matches stored username
  if (storedUsername != null && enteredUsername === storedUsername) {
    // Allow login to proceed
    return;
  }
  // Deny login if username doesn't match
  throw new Error('Invalid username or password here in customs.');

};

```

After creating this action, i have added it to trigger : **post-login**

But this is not working as expected, Why is this post login trigger not working ?

---

<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 10, 2025, 5:04pm UTC](https://community.auth0.com/t/post-login-trigger-not-working-as-expected/168128/3 "2025-01-10T17:04:42Z")

</div>

Hi @purva.jantikar,

I have just tested your post-login action script and got it to run. Some things you could check is in your Auth0 Logs to verify that the Action details in your login event executed.

Additionally, I recommend using the built-in actions debugger to test your action scripts before deployment. For more information, see our [Test Actions](https://auth0.com/docs/customize/actions/test-actions) documentation.

If you prefer to test in a legitimate login flow, you can use the [Real-time Webtask Logs Extension](https://auth0.com/docs/customize/extensions/real-time-webtask-logs).

Thanks,  
Rueben

---

<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:** [January 24, 2025, 5:05pm UTC](https://community.auth0.com/t/post-login-trigger-not-working-as-expected/168128/4 "2025-01-24T17:05:39Z")

</div>

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