# State Parameter Is Not Appended in Redirect User Action

**URL:** <https://community.auth0.com/t/state-parameter-is-not-appended-in-redirect-user-action/82874>\
**Category:** Get Help\
**Tags:** actions, state, redirect\
**Created:** [May 4, 2022, 12:42pm UTC](https://community.auth0.com/t/state-parameter-is-not-appended-in-redirect-user-action/82874 "2022-05-04T12:42:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![daboweiqi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/daboweiqi/32/37095_2.png) [@daboweiqi](https://community.auth0.com/u/daboweiqi)\
**Post date:** [May 4, 2022, 12:42pm UTC](https://community.auth0.com/t/state-parameter-is-not-appended-in-redirect-user-action/82874/1 "2022-05-04T12:42:15Z")

</div>

Hi there,

I’m trying to implement a customized 2FA for my login flow.  
I followed the document of using Action to redirect user to my 2FA page. It seems the state parameter is not appended in the URL so when I redirect the user back to my auth0 page, it gives an error saying state parameter is not found. If I give an arbitrary state parameter, it gives me a 401 error.

Here is my action code, and it’s very simple. I’ve been digging in this forum and the docs for a while. It seems no one else has this issue. I appreciate your help.

```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) => {
  // Craft a signed session token
  const session_token = api.redirect.encodeToken({
    secret: event.secrets.MY_REDIRECT_SECRET,
    expiresInSeconds: 60, 
    payload: {
      // Custom claims to be added to the token
      email: event.user.email,
    },
  });

  // Send the user to https://my-app.exampleco.com along
  // with a `session_token` query string param including
  // the email.
  api.redirect.sendUserTo("http://localhost:3000/api/auth/auth0", {
    query: {session_token}
  });
}

```

---

<div class="post-metadata">

**Author:** ![daboweiqi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/daboweiqi/32/37095_2.png) [@daboweiqi](https://community.auth0.com/u/daboweiqi)\
**Post date:** [May 4, 2022, 12:49pm UTC](https://community.auth0.com/t/state-parameter-is-not-appended-in-redirect-user-action/82874/2 "2022-05-04T12:49:09Z")

</div>

I also tried a simple example in the doc. The state parameter is not appended, either.

```auto
\\ code
exports.onExecutePostLogin = async (event, api) => {
  api.redirect.sendUserTo("https://my-app.exampleco.com");
};
\\ test output
[
  {
    "resumeFn": "onContinuePostLogin",
    "type": "RedirectPrompt",
    "url": "https://my-app.exampleco.com/"
  }
]

```

---

<div class="post-metadata">

**Author:** ![daboweiqi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/daboweiqi/32/37095_2.png) [@daboweiqi](https://community.auth0.com/u/daboweiqi)\
**Post date:** [May 4, 2022, 8:12pm UTC](https://community.auth0.com/t/state-parameter-is-not-appended-in-redirect-user-action/82874/3 "2022-05-04T20:12:45Z")

</div>

Okay, I finally found where the state resides. It’s in `event.transaction.state`.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [May 4, 2022, 9:34pm UTC](https://community.auth0.com/t/state-parameter-is-not-appended-in-redirect-user-action/82874/4 "2022-05-04T21:34:28Z")

</div>

Awesome, glad you were able to sort this out - Thanks for sharing with the community 🙂

---

<div class="post-metadata">

**Author:** ![daboweiqi](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/daboweiqi/32/37095_2.png) [@daboweiqi](https://community.auth0.com/u/daboweiqi)\
**Post date:** [May 5, 2022, 7:35pm UTC](https://community.auth0.com/t/state-parameter-is-not-appended-in-redirect-user-action/82874/5 "2022-05-05T19:35:10Z")

</div>

It would be helpful if you can update the document which says the state parameter is automatically appended to the URL.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [May 20, 2022, 7:35pm UTC](https://community.auth0.com/t/state-parameter-is-not-appended-in-redirect-user-action/82874/6 "2022-05-20T19:35:53Z")

</div>

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