Skip to content

Instantly share code, notes, and snippets.

@dnordberg
Forked from olizilla/meteor-account-verify.js
Created August 2, 2016 21:13
Show Gist options
  • Save dnordberg/b806f0a72017e1b3668d0300316c14c3 to your computer and use it in GitHub Desktop.
Save dnordberg/b806f0a72017e1b3668d0300316c14c3 to your computer and use it in GitHub Desktop.
Only allow users on a given email domain to log in to your meteor app.
/*
Only allow users with a verified email address on a pre-verified domain to log in.
We're getting people to authenticate and only authorising those that have an email we recognise.
Assumes a Meteor.settings like:
{ adminDomains: ['tableflip.io', 'meteor.com'] }
...and meteor-developer accounts, but other login mechanisms (email, twitter) would work too.
*/
// Only allow logins for `adminDomain` users
Accounts.validateLoginAttempt(function (info) {
return canHasAccess(info.user)
})
function canHasAccess (user) {
if (!user) return false
if (!user.services['meteor-developer'].emails) return false
return user.services['meteor-developer'].emails.some(verifyEmail)
}
// Check the email is part of a domain configured with admin rights
function verifyEmail (email) {
if (!email.verified) return false
var emailDomain = email.address.split('@')[1]
var adminDomains = Meteor.settings.adminDomains
return adminDomains.some(function (adminDomain) {
return emailDomain === adminDomain
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment