Allow only specific users to login using everyauth
Problem
I have an expressjs app with Everyauth setup.
Everyauth is working fine. Now, I want everyauth to allow users to Login into the app whose email id matches a regular expression.
Say I want people to login whose email starts with the letter "foo" (suppose, [email protected]) or is of a specific domain like adeptocorp.com (suppose [email protected])
Kindly provide me some solution to solve this situation
Solution
If you use password authentication (which I presume cause otherwise you don't have to care about e-mail addresses) then you can use the validateRegistration
function.
For others, write a piece of connect middleware like:
function checkEmail(regex){
return function (req, res, next) {
// get everyauth.user via the everyauth helper
if (!everyauth.user.email.test(regex)) {
res.writeHead(403);
res.end("e-mail address not allowed");
}
else { next(); }
}
};
And use it right after the everyauth
use like:
connect // or express
...
.use(checkEmail)
Discussion
View additional discussion.