Save social users to database

Hello! I have a custom database setup that saves my email password users to a mysql database. I need users that sign up with social to be saved to the database as well. How does one go about doing that?

Hi @jake6

Thanks for getting in touch with us at Auth0 Community.

You might be able to use a Login Action. Pick up a first login, detect if it’s a social login and if so then log the user to the your mysql database. You may be able to use the bulk of the code from you custom db script, secrets can be stored against the Action too.

Something like the below might get you started.

exports.onExecutePostLogin = async (event, api) => {
  const is_social = event.connection.strategy === event.connection.name;
  // if it is the first login and it is a social login
  if (event.stats.logins_count === 1 && is_social) {
    console.log(event.user.email);
    //insert record into mysql db
  }
};

Regards

1 Like