node.js - Firebase admin.auth().getUser(uid) hangs (NodeJS) -
i'm using admin.auth().getuser(uid) in firebase admin sdk (nodejs), in serverless project, , return result. though function returns result, lambda still doesn't terminate , have use ctrl+c end it.
here's full code of function (in typescript):
public getuser(uid: string): { console.log('firebasemanager getuser method start'); const self: firebasemanager = this; const promise: = 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 i'm doing wrong?
note if comment out admin.auth().getuser(uid) block (and replace promise.resolve("ok")
), function terminate properly. mean, doesn't hang (but it's bit useless ^^):
public getuser(uid: string): { console.log('firebasemanager getuser method start'); const self: firebasemanager = this; const promise: = 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)
apparently, need run admin.app().delete();
, otherwise connection firebase remains active, preventing process terminating.
so in example code, considering not need use firebase anymore after running function:
public getuser(uid: string): { console.log('firebasemanager getuser method start'); const self: firebasemanager = this; const promise: = self.getdeferred(); admin.auth().getuser(uid) .then(function(userrecord: admin.auth.userrecord) { console.log("successfully fetched user data:", userrecord); admin.app().delete(); promise.resolve(userrecord); }) .catch(function(error: firebaseerror) { console.log("error fetching user data:", error.errorinfo); admin.app().delete(); promise.reject('error getting firebase user ' + uid); }); return promise.promise; }
Comments
Post a Comment