# Invalid redirect URL even if state paramater addedd

**URL:** <https://community.auth0.com/t/invalid-redirect-url-even-if-state-paramater-addedd/152260>\
**Category:** Get Help\
**Tags:** signup-prompt-new-experience, login-experience\
**Created:** [November 22, 2024, 10:27am UTC](https://community.auth0.com/t/invalid-redirect-url-even-if-state-paramater-addedd/152260 "2024-11-22T10:27:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![csokan.raul89](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/csokan.raul89/32/60395_2.png) [@csokan.raul89](https://community.auth0.com/u/csokan.raul89)\
**Post date:** [November 22, 2024, 10:27am UTC](https://community.auth0.com/t/invalid-redirect-url-even-if-state-paramater-addedd/152260/1 "2024-11-22T10:27:17Z")

</div>

Greetings again, @dawid.matuszczyk @rueben.tiow

The question is, that is this code from my action legit, becasue I always receive Invalid Redirect URL when launching my post-login action:

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (event.user.app_metadata["demo_account"] === true && 
   event.user.app_metadata["had_demo"] === false && 
   event.user.app_metadata["demo_expired"] == false && 
   event.user.app_metadata["db_record"] === false) {
    const id = event.user.user_id;
    const email = event.user.email;
    const state = event.transaction?.state
    api.redirect.sendUserTo(`${event.secrets.MAIN_DOMAIN}/verify?auth0Sub=${id}&email=${email}&state=${state}`);
   }
};

exports.onContinuePostLogin = async (event, api) => {
  const state = event?.transaction?.state
  api.user.setAppMetadata("db_record", true);
  api.redirect.sendUserTo(`${event.secrets.AUTH0_ISSUER_BASE_URL}/continue?state=${state}`);
};

```

The reason I don’t understand the error, that when I simply copy-paste the url from the ExecutePostLogin function, it just works, but when launching through Auth0 tenant url, it’s not working.

What am I missing here?

Help is much appreciated!

---

<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 22, 2024, 9:11pm UTC](https://community.auth0.com/t/invalid-redirect-url-even-if-state-paramater-addedd/152260/3 "2024-11-22T21:11:16Z")

</div>

Hi @csokan.raul89,

The error you experienced seems to originate from the redirect URL you used.

I am unable to verify what values you have set for your `event.secrets.MAIN_DOMAIN`; however, the error indicates that there is an issue with the URL that you are trying to redirect to.

In this situation, I recommend ensuring that the URL is valid by debugging it with `console.log()` statements and using the [Real-time Webtask Logs Extension](https://auth0.com/docs/customize/extensions/real-time-webtask-logs) during a regular login flow.

Please also ensure that your URL includes `http://` or `https://` prepended in the URL.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![csokan.raul89](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/csokan.raul89/32/60395_2.png) [@csokan.raul89](https://community.auth0.com/u/csokan.raul89)\
**Post date:** [November 23, 2024, 6:49am UTC](https://community.auth0.com/t/invalid-redirect-url-even-if-state-paramater-addedd/152260/4 "2024-11-23T06:49:50Z")

</div>

Well, the MAIN\_DOMAIN should be [http://localhost:3000](http://localhost:3000) and the AUTH0\_ISSUER\_BASE\_URL is my tenant address.

Here’s what I get in the browser:  
In the URL bar it’s my tenant address with the authorize endpoint and other parameters,  
while instead of the page this is what i get:

```auto
Invalid redirect URL http://localhost:3000/verify?auth0Sub=REDACTED_USER_ID&email=REDACTED_EMAIL&state=REDACTED_STATE

```

And I noticed that state value is the same as it was yesterday when I tried it.

The main idea that occurred to me right now, is that to redirect the user from the post-login action to this custom verification page with the user\_id and email as parameters and create a database record out of it, then inside this custom page i add a redirect command to the AUTH0 tenant address with the continue endpoint + the state extracted from the previous step, ubt no lcuk either.

---

<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 25, 2024, 11:47pm UTC](https://community.auth0.com/t/invalid-redirect-url-even-if-state-paramater-addedd/152260/5 "2024-11-25T23:47:27Z")

</div>

Hi @csokan.raul89,

Have you had a chance to use the Test button within the Auth0 Action interface?

 ![image](https://global.discourse-cdn.com/auth0/original/3X/e/7/e71e781e30128c6a5790385c8c5645cd7bf3d4a7.png)

I just tried testing your URL `http://localhost:3000/verify?auth0Sub=REDACTED_USER_ID&email=REDACTED_EMAIL&state=REDACTED_STATE` in a post-login action script interface and did not get an invalid redirect URL error.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/d/f/df80a8b4030c5ed36f1e44ef79d85bf097defb7d.png)

Yes, you have understood this correctly. After redirecting the user, you must send them back to the `/continue?state=YOURSTATE` endpoint to resume the authentication flow.

---

<div class="post-metadata">

**Author:** ![csokan.raul89](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/csokan.raul89/32/60395_2.png) [@csokan.raul89](https://community.auth0.com/u/csokan.raul89)\
**Post date:** [November 28, 2024, 7:45am UTC](https://community.auth0.com/t/invalid-redirect-url-even-if-state-paramater-addedd/152260/6 "2024-11-28T07:45:19Z")

</div>

@rueben.tiow I don’t know why did I get this invalid redirect URL in Nextjs, but I fogured out another way to obtain access tokens and store thrm and save metadata into the users Auth0 profile.

I only use pre-registration flow and after obtaining access tokens i created a custom page which saves specific data for the user profile.

Yet, i will take some time to explore why did i get that error.  
For reference, i had misspelled the tenant url, but even afte tixing it the error still occured, so i still want to look into this later.

May I ask what was your approach in the testing?

---

<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 2, 2024, 10:28pm UTC](https://community.auth0.com/t/invalid-redirect-url-even-if-state-paramater-addedd/152260/7 "2024-12-02T22:28:43Z")

</div>

Hi @csokan.raul89,

Thanks for the update.

Aha, it makes sense that a misspelled URL was causing an error as well.

> [@csokan.raul89](#):
>
> May I ask what was your approach in the testing?

When you navigate to your Action script on the [Dashboard \> Actions \> Triggers \> pre-user-registration](https://manage.auth0.com/#/actions/triggers/pre-user-registration/) and select your Action script, on the script interface, there is a Test button as shown in my previous reply’s screenshot.

On there, you can test your action script without going through a sign up flow. This way, you can debug your action script and ensure it works correctly before deployment.

Let me know if you still encounter issues.

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:** [December 16, 2024, 10:28pm UTC](https://community.auth0.com/t/invalid-redirect-url-even-if-state-paramater-addedd/152260/8 "2024-12-16T22:28:55Z")

</div>

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