How can I distinguish between SNS login and username-password login?

As title.
Can somebody show me how to distinguish between SNS login and username-password login ?
I’d like the flow like below:

  • Login with Auth0 (using my own database with custom create action scripts)
  • Backend receive the callbacks
  • Distinguish SNS login or username-password

I think there must be doing something with the callbacks in action scripts but can somebody show me how?

Hi @quanlm,

One strategy you could employ is to add the connection name as a custom claim.

This way, when a user has logged in with either an SNS login or your custom database, you can verify that information in the decoded access token claims.

For example:

exports.onExecutePostLogin = async (event, api) => {
  
  const namespace = 'https://myapp.example.com';
  const { connection } = event;
  
  if (event.connection.name === 'Your-Custom-DB') {
    api.idToken.setCustomClaim('${namespace}/login_method', 'Your-Custom-DB');
  } else {
    api.idToken.setCustomClaim('${namespace}/login_method', 'SNS');
  }
};

Thanks,
Rueben

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