Meteor application that only allows Google login by pre-approved e-mail addresses.
// Make sure that the user should be able to login and delete temp account
Accounts.validateNewUser(function(user) {
var usr = Accounts.findUserByEmail(user.services.google.email);
if (usr) {
Meteor.users.remove(usr._id);
return true;
}
return false;
});
// Merge info from temp account
Accounts.onCreateUser(function(options, user) {
var usr = Accounts.findUserByEmail(user.services.google.email);
if (usr) { user = Object.assign({}, usr, user); }
if (options.profile) { user.profile = options.profile; }
return user;
});
Template.login.events({
'click #google-login': function(e, template) {
Meteor.loginWithGoogle({ requestPermissions: ['email'] }, function(error){
if (!error) {
Router.go('/');
} else {
alert('You do not have permission to log in.');
}
});
}
});
<template name="login">
<div class="login-box">
<h1>Welcome</h1>
<a href="#" id="google-login"><img src="img/google-signin.png"></a>
</div>
</template>