[Vuejs]-Function doesn't "wait" for valid information before querying database

0👍

rewrite getUserId to return a Promise

function getUserId() {
    return new Promise((resolve, reject) => {
        getAuth().onAuthStateChanged((user) => {
            if (user) {
                const uid = user.uid;
                console.log("1st uid:" + uid);
                resolve(uid);
                
            } else {
                console.log("sad didnt work.");
                reject();
            }
        });
    });
}

Leave a comment