Help me with redirect to login after password change

Hi everyone. I need urgent help.

I implemented auth0 login in my project. I called loginWithRedirect and opened auth0 login form. And in login action I wrote this code to redirect to password reset page.

exports.onExecutePostLogin = async (event, api) => {
if (event?.user?.user_metadata?.is_password_temp) {
const tokenResponse = await fetch(\`https://tenant_domain/oauth/token\`, {

  method: 'POST',

  headers: { 'Content-Type': 'application/json' },

  body: JSON.stringify({

    client_id: 'm2m client id',

    client_secret: ‘m2m client secret‘,

    audience: \`audience goes here\`,

    grant_type: 'client_credentials'

  })

});

if (!tokenResponse.ok) {

  throw new Error(\`Failed to fetch access token: ${tokenResponse.statusText}\`);

}

const tokenData = await tokenResponse.json();

const accessToken = tokenData.access_token;

const ticketResponse = await fetch(\`https://terman domain/api/v2/tickets/password-change\`, {

  method: 'POST',

  headers: {

    'Authorization': \`Bearer ${accessToken}\`,

    'Content-Type': 'application/json'

  },

  body: JSON.stringify({

    client_id: 'spa client id',

    user_id: event.user.user_id

  })

});



const ticketData = await ticketResponse.json();

const resetUrl = ticketData.ticket;

api.redirect.sendUserTo(

  resetUrl

);
}

};

This code work well and redirected to password reset page after login success.

I blocked here. After success password reset, I need to go auth0 login page directly again. How should I do?

Hi @roman.savchuk

Welcome to the Auth0 Community!

In order to have the user redirected to the application’s login page, you will need to configure a default login route.

You can do that by going to your application within the Auth0 Dashboard → Settings → Application Login URI or you can configure a tenant wide one by going to the Dashboard → Settings → Advanced → Tenant Login URI. These will display a button on the password reset success page which will redirect them to the login page again. Unfortunately, it is not possible to redirect the user automatically once they have successfully reset they password unless this functionality is handled within a custom page and not by Auth0’s Universal Login.

If you have any other questions, let me know!

Kind Regards,
Nik

Thanks for your reply. I want to go auth0 login page after password reset success by clicking link.

So according to your reply, I think I need to set tenant login url here.

Dashboard → Settings → Advanced → Tenant Login URI

for example if my tenant main url is example.us.auth0.com, what url I should set for tenant login url?

https://example.us.auth0.com? or https://example.us.auth0.com/u/login?

Hi again!

The URL should be the one pointing to your /authorize endpoint of your application. In most instances, this should be https://example.us.auth0.com/u/login.

Kind Regards,
Nik

Thanks for your reply. I added https://example.us.auth0.com/u/login in ternalt login uri. of course I used my tenant domain. But I still can not see link on password reset page.

Ok. If this is impossible I will turn on app manually after password reset success.

And I need other difficult on my project. My project is angular+ionic+capacitor project.

In development mode, I use google chrome.

If I call loginWithRedirect function when click button, auth0 login page displayed and after login success returned to http://localhost:8100 automatically. Of course I added http://localhost:8100 in allowed web origins, allowed callback urls, allowed logout urls on auth0 dashboard. and As redirect url, I setted http://localhost:8100 in my project. But this is development mode. I need to do the same thing in production mode- on emulator and real phone, not web browser.

In this case what url should I use for redirect url?

Thanks.