1
votes

I am using AUTH0 V9 API to host the login page on my website and use API to login user via AUTH0. I am using https://auth0.com/docs/libraries/auth0js document as a reference. I installed the auth0-js npm package via the following command

npm install auth0-js

Then initialized the AUTH0 via the following code

<script type="text/javascript">
 var webAuth = new auth0.WebAuth({
  domain:       'YOUR_DOMAIN',
  clientID:     'YOUR_CLIENT_ID'
  redirectUri: "http://localhost:3000/login",
  responseType: "code",
  responseMode: "form_post",
  scope: "openid profile email",
 });
</script>

Then I using login() method as following

webAuth.login({
 realm: 'tests',
 username: 'testuser',
 password: 'testpass',
});

But this above login code is not working. It's redirecting me to some other URL and not to "http://localhost:3000/login" which I provided while initializing AUTH0 object.

This method also has a reference to "Custom Domain". Do I need to purchase AUTH0 subscription for managing V9 API or I am doing something wrong that's why I am getting the wrong redirect. Please help.

========

Some strange thing I discovered that the same code is working with my personal account but not with my client's business account.

1
Forgot to mention that I am using nextJS - Nitesh Malviya
You also need to configure your app at Auth0 website. - Fahima Mokhtari
Yes I already did. I created a "Web application" type app and added callback ad CORS URLs as "localhost:3000". I am not getting CORS error too. The problem is that it does not redirect to the "RedirectURI" which I have given. It redirects to some other URL - Nitesh Malviya
Did you set the callback URL and origin URL? The problem is probably there - Fahima Mokhtari
Here's my configuration: Allowed Callback URLs: localhost:3000/callback ; Allowed Web Origins:localhost:3000 ; Allowed Origins (CORS): localhost:3000 . Hope this helps - Fahima Mokhtari

1 Answers

1
votes

The same code mentioned above worked with my personal account but not with my client's business account and the problem was that client had set up custom error pages in the tenant settings. Whosoever is working with custom login, please check out two things.

  1. Your callback URL is exactly what you are mentioning in your custom login code via AUTH0 V9.
  2. Custom error pages are off in the tenant settings. "Tenant settings -> General Pages -> Error".