I set up Passwordless Email authentication. I implemented a “Pre User Registration” flow action to restrict which email addresses can register. I wasn’t able to show the error message from this action, but using “Customize Login Page” in Universal Login > Advanced Options, I updated languageDictionary to change the error message displayed when an error occurred.
I have managed to do it on the classic universal login this is the action
exports.onExecutePreUserRegistration = async (event, api) => {
const ManagementClient = require('auth0').ManagementClient;
const management = new ManagementClient({
domain: event.secrets.domain,
clientId: event.secrets.clientId,
clientSecret: event.secrets.clientSecret,
});
try {
const users = await management.usersByEmail.getByEmail({email:`${event.user.email}` });
if (users.data.length >= 1) {
api.access.deny("duplicate_email", "An account with that email already exists, please use another email or go back and sign in instead.");
}
}
catch(e) {
console.error(e)
}
};
And then on the customized HTML of the login
lock.on('signup error', function(error) {
const originalError = error?.original?.response?.body;
// if we get error back from Auth0 Actions, this code makes sure the error is written in the red error banner
if (originalError.code === 'extensibility_error') {
const message = originalError.friendly_message;
const spanElement = document.querySelector('.auth0-global-message');
spanElement.textContent = message;
}
});
And there you go you see the message … it’s not great because things could change which we have no control over but again … it works