简体   繁体   中英

Firebase cloud funtions get user UID

I have written a firebase cloud function to get registered user UID once the user is successfully registered.

but the code doesn't return UID and returns empty. can any one help me with this I believe the auth.user is unable get UID. has anyone written a code to get UID?

exports.sendOTB = functions.auth.user().onCreate((event) => {
    firebase.auth().onAuthStateChanged(function(user) {
        if (user) {
            userID = user.uid;
            // User is signed in.
        } else {
            // No user is signed in.
        }
    }
});

Try this:

exports.sendOTB = functions.auth.user().onCreate((event) => {

 const user = event.data;
 const email = user.email;
 const userid = user.uid;

 });

more info here:

https://firebase.google.com/docs/reference/functions/functions.auth.UserRecord

Also according to this answer:

https://stackoverflow.com/a/46452975/7015400

you cannot know events for login in cloud functions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM