Hello,
I’ve created 2 custom actions that only allow specific email domains to be used for login/signup.
Login flow
exports.onExecutePostLogin = async (event, api) => {
const emailDomain = event?.user?.email?.split('@')?.[1] || ''
const allowedDomains = ['mydomain.com']
if (!allowedDomains.includes(emailDomain)) {
api.access.deny(`Email domain "${emailDomain}" is not allowed.`)
}
};
Pre-Registration flow
exports.onExecutePreUserRegistration = async (event, api) => {
const emailDomain = event?.user?.email?.split('@')?.[1] || ''
const allowedDomains = ['mydomain.com']
if (!allowedDomains.includes(emailDomain)) {
api.access.deny(`Email domain "${emailDomain}" is not allowed.`, 'Access denied')
}
};
When trying to login/signup via Username-Password-Authentication with a domain other than the specified ones, Auth0 returns the error message to the login form, and everything works fine.
The problem is when users try to login/signup via OAuth2 Social Providers like google-oauth2:
- The Pre-Registration flow does not run for social providers (common Auth0 behaviour)
- The Login flow runs and it logs the “login error” in the logs, but the user is still created in the tenant
Is this the expected flow? I was expecting users to not be created in the Auth0 tenant if any of the actions fails.
Thank you in advance!