Created
August 21, 2019 11:33
-
-
Save Tanver-Hasan/1b34a848ede54a5c97d146341b486abe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function (user, context, callback) { | |
var ManagementClient = require("[email protected]").ManagementClient; | |
var mgt = new ManagementClient({ | |
domain: "{auth0 domain}", | |
clientId: "{client ID}", | |
clientSecret: "{Client secret}", | |
audience: "https://{auth0 domain}/api/v2/" | |
}); | |
mgt.getUsersByEmail(user.email).then(res => { | |
console.log("checking user exist or not"); | |
if (res.length >= 1 || res !== null || res !== "") { | |
console.log(user.user_id); | |
mgt.deleteUser({id:user.user_id}).then(res => { | |
console.log("Deleting user"); | |
console.log(res); | |
return callback(new UnauthorizedError("Access Denied - An account already exist")); | |
}).catch(err => { | |
console.log("Failed to delete user"); | |
console.log(err); | |
}); | |
} | |
}).catch(err => { | |
console.log(err); | |
}); | |
callback(null, user, context); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment