I'm using admin.auth().getUser(uid) in the Firebase Admin SDK (NodeJS), in a Serverless project, and it does successfully return a result. But even though my function returns the result, my lambda still doesn't terminate and I have to use CTRL+C to end it.
Here's the full code of my function (in TypeScript):
public getUser(uid: string): any {
console.log('FirebaseManager getUser method start');
const self: FirebaseManager = this;
const promise: any = self.getDeferred();
admin.auth().getUser(uid)
.then(function(userRecord: admin.auth.UserRecord) {
console.log("Successfully fetched user data:", userRecord);
promise.resolve(userRecord);
})
.catch(function(error: FirebaseError) {
console.log("Error fetching user data:", error.errorInfo);
promise.reject('Error getting Firebase user ' + uid);
});
return promise.promise;
}
Is there something I'm doing wrong?
Note that if I comment out the admin.auth().getUser(uid) block (and replace it with promise.resolve("ok")
), my function does terminate properly. I mean, this doesn't hang (but it's a bit useless ^^):
public getUser(uid: string): any {
console.log('FirebaseManager getUser method start');
const self: FirebaseManager = this;
const promise: any = self.getDeferred();
promise.resolve("ok");
return promise.promise;
}
I'm using Serverless 1.21.1, Typescript 2.5.2, Node 6.11.3 or 8.4.0 (2 different dev environments, both same result)