Skip to content

Instantly share code, notes, and snippets.

@rubyist
Created May 30, 2013 15:35
Show Gist options
  • Save rubyist/5678817 to your computer and use it in GitHub Desktop.
Save rubyist/5678817 to your computer and use it in GitHub Desktop.
I have a Meteor app that authenticates against Google for logging in. I also have a cucumber suite that runs against the app and I don't want it to go through the Google auth. This setup will check a KIT_ENV environment variable, and if it is "test" (i.e. being run for the cucumber suite) it will just run an anonymous login and setup a default u…
var attemptLogin = function() {
var validateResult = function(e, result) {
if (e) {
Meteor.loginWithGoogle();
}
};
Accounts.callLoginMethod({methodArguments: [{}], userCallback: validateResult});
};
Template.login.events({
'click #login': function(e) {
e.preventDefault();
attemptLogin();
}
});
Accounts.registerLoginHandler(function (options) {
if (process.env.KIT_ENV !== 'test') {
return undefined; // Don't handle 'anonymous' login
}
var stampedLoginToken = Accounts._generateStampedLoginToken();
var anonUserId = '';
var anonUser = Meteor.users.findOne({username: 'anon-test'});
if (anonUser) {
anonUserId = anonUser._id;
} else {
anonUserId = Meteor.users.insert({username: 'anon-test'});
}
Meteor.users.update(
anonUserId, {$push: {'services.resume.loginTokens': stampedLoginToken}});
return {token: stampedLoginToken.token, id: anonUserId};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment