Created
June 27, 2022 10:03
-
-
Save kevcodez/c0fd2bfbd896de863e24980084f78054 to your computer and use it in GitHub Desktop.
Auth0 notify backend on social auth "registration"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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