@earnaha/auth0-action-helper
Version:
AHA auth0 action helper
39 lines (35 loc) • 1.31 kB
JavaScript
/* eslint-disable no-unused-vars */
const BaseHelper = require('./base.js');
class PreUserRegistrationHelper extends BaseHelper {
/**
* https://auth0.com/docs/customize/actions/flows-and-triggers/pre-user-registration-flow
* Handler that will be called during the execution of a PreUserRegistration flow.
* @param {Event} event - Details about the context and user that is attempting to register.
* @param {PreUserRegistrationAPI} api - Interface whose methods can be used to change the behavior of the signup.
*/
async exec(event, api) {
super.LOGGER.setMeta({
email: event?.user?.email,
connection: event?.connection?.name,
});
// TIP: in this action, user hasn't complete created
// i.e. event.user doesn't have user_id
const connName = event?.connection?.name;
if (connName && connName === super.DEFAULT_CONN) {
const userToken = await super.getUserToken();
const existingUsers = await super.formUsersHavingTheSameEmail(
event,
userToken,
);
super.LOG.debug(
{ existingUsers },
`PreUserRegistration.exec | existing users`,
);
// 3rd-party-auth users having the same email already exist!!
if (existingUsers.otherAuthUsers.length > 0) {
api.access.deny('Account already in use.');
}
}
}
}
module.exports = PreUserRegistrationHelper;