DEV Community

Discussion on: Vue, guard routes with Firebase Authentication

Collapse
 
gautemeekolsen profile image
Gaute Meek Olsen

Usually, TS won't let you add a method to another object without something additional.

But maybe you can just assign the method to a new variable instead:

const getCurrentUser = () => {
    return new Promise((resolve, reject) => {
        const unsubscribe = firebase.auth().onAuthStateChanged(user => {
            unsubscribe();
            resolve(user);
        }, reject);
    })
};
Enter fullscreen mode Exit fullscreen mode
Collapse
 
chromaticranger profile image
Martin Stickley

I can confirm that this approach worked for me in TS. :-) Many thanks @gautemeekolsen for sharing this knowledge.