Saturday 21 December 2019

Trying to understand AdminFS

I already have this setup in other areas and through poking and prodding I've gotten it to work in those areas, but I still don't understand what is going wrong. I am hoping someone can explain it to me. Here is the Firebase Admin Firestore code: -async function that is also middleware- let user; await adminFS.collection('users').doc(req.body.uid).get().then(doc => { if (!doc.exists) console.log('User not found.'); else { try{ user = { uid: doc.uid, email: doc.email, displayName: doc.displayName, subscriptionLevel: doc.subscriptionLevel, subscriptionID: doc.subscriptionID, admin: doc.admin, token: doc.token } console.log(doc); console.log(user); } catch (err){ console.log(err, err.stack) } } console.log(user); }); console.log(user) So, console.log(doc) will give me all the information I need but also information I don't need but if I use something like token.uid it will be undefined. The first console.log(user) will result in nothing even though (in my mind) user should have been just defined. Even after the if statement has completed, the user is still undefined. Even after using Async and Await, which should force it to be sequential, user is still undefined.

Submitted December 21, 2019 at 06:25PM by sinithw

No comments:

Post a Comment