How do a signIn with Auth0 npm package?

We are looking to adopt Auth0 for a single sign-on for multiple apps but we have some existing users in our database. On the server-side we would like to attempt to login to our database with the user’s email and password and if unsuccessful attempt a login to Auth0.

I found the auth0 npm package and the AuthenticationClient class but I’m not able to use it successfully based on the documented example - all my attempts fail with SignIn failed: Invalid email or password. My code is below -

const AuthenticationClient = require('auth0').AuthenticationClient;
...
const auth0 = new AuthenticationClient({
  domain: 'xxxxxxxxxx.auth0.com'
});
const data = {
  username: email,
  password: password
 };
try {
  const { error, response, user } = await auth0.oauth.signIn(data);
  return user;
} catch(e) {
   console.log(e)
}

I have also tried using multiple connections on the App client in Auth0 where the database connection is connected to a remotely, hosted DB and another connection to a SAML Identity Provider hosted in Auth0. But Auth0 does not support a round robin login when there are multiple connections. Is this true?

Focusing on the first paragraph of your question what you describe is very similar to what’s given by a custom database connection with import mode enabled. This setup would allow to transparently migrate your existing users to the Auth0 user store. If on the other end you want to keep using your own store to keep the current and future user credentials then you would use a custom database connection without import mode. The important point is that there would only be a single database connection.

For reference information on both possibilities see:

With regards to the issue with the SDK the method in question makes use of a deprecated endpoint so I would not even recommend trying to make use of it. As to what you should use instead that mostly depends on the characteristics of the client applications so there’s insufficient information to answer that.

Thank you @jmangelo. What I wanted was to see if we could keep our sign-in page by using Auth0 programmatically on the server-side - it looks like that’s not the case.

Thank you @jmangelo. What I wanted was to see if we could keep our sign-in page by using Auth0 programmatically on the server-side - it looks like that’s not the case.

It’s possible, you should use a non-deprecated endpoint (see https://auth0.com/docs/api/authentication#resource-owner-password). You could use that endpoint to target the custom database connection that would then if needed call into the existing store.

i tried and it doesn’t work - still getting invalid username and password but i’m able to sign in using the hosted page

Using the endpoint above be sure to use the realm parameter (requires adjusting the grant type also) to specify the exact database connection associated with the user; otherwise the endpoint will use the default connection configured at the tenant level which might not be correct.