Created
May 30, 2013 15:35
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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