Skip to content

Instantly share code, notes, and snippets.

@kevcodez
Created June 27, 2022 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevcodez/c0fd2bfbd896de863e24980084f78054 to your computer and use it in GitHub Desktop.
Save kevcodez/c0fd2bfbd896de863e24980084f78054 to your computer and use it in GitHub Desktop.
Auth0 notify backend on social auth "registration"
async function (user, context, callback) {
const axios = require('axios');
const isSocial = context.connectionStrategy === context.connection;
// if it is the first login (hence the `signup`) and it is a social login
if (context.stats.loginsCount === 1 && isSocial) {
let loginMethod = '';
const connectionName = user.identities[0].provider.toLowerCase();
if (connectionName.includes('google')) {
loginMethod = 'Google';
} else if (connectionName.includes('apple')) {
loginMethod = 'Apple';
} else if (connectionName.includes('facebook')) {
loginMethod = 'Facebook';
}
return axios.post('https://your.api', {
email: user.email,
userId: user.identities[0].user_id,
provider: 'Auth0',
loginMethod,
socialProviderId: user.identities[0].user_id,
},
{
headers: {
...
}
}).catch(console.error)
.finally(() => {
// always let the user login, no matter if an error happens
return callback(null, user, context);
});
} else {
return callback(null, user, context);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment