You might want ot use beforeSignIn
wich is a blocking function. It will block signing if an exception is thrown. You can still us it to execute some other stuff.
exports.myFunction = functions.auth.user().beforeSignIn((user, context) => {
// your logic, user.uid available
});
Doc : https://firebase.google.com/docs/auth/extend-with-blocking-functions