I have a application, in which a user can login with google and email password method.
But we have specific need that if a user is already signed up, say with google. then he won’t be allowed to create a account using email and password method. How I can do this?
Hello,
You can use the Management API within Auth0 Pre-Registration Action to check if the user with the same email already exists in another connection:
Here’s the sample Pre-registration Action you can create :
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,
});
management.getUsers({q: `email:"${event.user.email}"` },function (err, users) {
if (users.length >= 1) {
api.access.deny("The user with this email already exists");
}
});
}
I recommend installing the Real-Time Log Extension to debug Auth0 Extensibility such as Actions, Hooks and Rules.
I hope this helps!
system
Closed
January 6, 2023, 8:06pm
3
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.