Skip to content

Instantly share code, notes, and snippets.

@katopz
Last active September 7, 2015 05:45
Show Gist options
  • Save katopz/91b3f9596e6c74d5cbbf to your computer and use it in GitHub Desktop.
Save katopz/91b3f9596e6c74d5cbbf to your computer and use it in GitHub Desktop.
Async call to authen Firebase via Meteor
// https://github.com/firebase/firebase-token-generator-node
Meteor.methods({
enterChat: function (userId) {
if (!userId) {
throw new Meteor.Error("not-logged-in",
"Must be logged in to enter chat.");
}
var authWithCustomToken = Meteor.wrapAsync(function (userId, callback) {
var FirebaseTokenGenerator = Meteor.npmRequire("firebase-token-generator");
var tokenGenerator = new FirebaseTokenGenerator("YOUR_FIREBASE_SECRET");
var token = tokenGenerator.createToken({uid: userId});
console.log("uid : " + userId);
console.log("token : " + token);
var Firebase = Meteor.npmRequire("firebase");
var firebase = new Firebase('https://radiant-fire-foo.firebaseio.com/');
firebase.authWithCustomToken(token, function (error, authData) {
callback(error, {response: authData});
});
});
return authWithCustomToken(userId);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment