Last active
September 7, 2015 05:45
-
-
Save katopz/91b3f9596e6c74d5cbbf to your computer and use it in GitHub Desktop.
Async call to authen Firebase via Meteor
This file contains 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
// 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