Problems with postlogin actions

I have a problem. I want my users to register to be redirected to an additional information page. I think the only way to do this is by using a post login action
this is my action

exports.onExecutePostLogin = async(event, api) => {
  if(event.stats.logins_count === 1){
    api.redirect.sendUserTo("http://localhost:5173/Additional-information")
  } else{
  }
};

I need that if the user starts a section, he returns to the page where he was before. How can I do that?

Hi @hugo127sanchez.

Welcome to the Auth0 Community!

I understand that you’ve been experiencing some difficulty with getting a Redirect Action to work in a Post Login Action script.

After reviewing your script, I noticed that there’s a missing code snippet that is necessary for resuming authentication from your redirect URL. It’s an important step, so let me guide you through it.

In your code, you will need to include the onContinuePostLogin function. Please take a look at the updated script below:

exports.onExecutePostLogin = async (event, api) => {
  if (event.stats.logins_count === 1) {
    api.redirect.sendUserTo("http://localhost:5173/Additional-information");
  }
};

exports.onContinuePostLogin = async (event, api) => {
  // Add any necessary code here for resuming authentication
};

Then to return the user back to your application and resume the login transaction, you must take the state parameter that was appended in your redirect URL and pass it back to your /continue endpoint.

Here’s how the flow should look like:

  1. The user logs in to your application.
  2. They get redirected to your additional information page with a state parameter.
  3. After the user completes adding the required information, you should send them back to the /continue endpoint. For example: https://{yourAuth0Domain}/continue?state=THE_ORIGINAL_STATE

For more detailed information, I recommend referring to our documentation on Redirect Actions. It provides additional insights that can be helpful in understanding the process.

Please let me know if you have any questions.

Thanks,

Rueben

Hi, good morning, Ruben. In the end I decided to use the loginWithRedirect function. Since I do not understand the use of the actions well, since when after registering or logging in with any of those users, it does not let me make any authentication request. I think the problem is because when using my action at no time after the registrar does my app go through the /consent. I have doubts about how to use the loginWithRedirect to have two redirect_uri one for the singup and another for the login. but for this I made another topic. Thank you very much for answering and sorry for the inconvenience

Hi @hugo127sanchez,

Thank you for your reply.

Unfortunately, it is not possible to use the loginWithRedirect function with two redirect_uri URLs.

Once the sign-up process is completed, the user is automatically logged in, and there is no distinction between the two actions in terms of redirecting to different pages. The loginWithRedirect function is designed to accept only one redirect_uri value as a string for the authorization parameter.

I hope this explanation clears up any confusion!

I also noticed that you have created a new post regarding this issue here, and I will continue the discussion there to provide further assistance.

Thanks,
Rueben

thank you! Yes, in the end I managed to do as you indicated but I have another problem with the getAccessTokenSilently when registering. That’s why there was the other thread. again thank you very much for your attention

1 Like

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