Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Allow only specific users to login using everyauth

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

Problem courtesy of: ArjunUrs

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)
Solution courtesy of: Jan Jongboom

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Allow only specific users to login using everyauth

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×