DEV Community

Discussion on: Vue, guard routes with Firebase Authentication

Collapse
 
franyerhiguerey profile image
Franyer Higuerey

Hello! it's pretty well, if you are in firebase 9 is the same, but only you have to create a new function without call "firebase.getCurrentUser" and importing like this:

import { onAuthStateChanged } from 'firebase/auth'
import { auth } from 'src/firebase'

const user = () => {
return new Promise((resolve, reject) => {
const unsubscribe = onAuthStateChanged(auth, (userFirebase) => {
unsubscribe()
resolve(userFirebase)
}, reject)

})
}

and later when you going to call it in a function has to be async obviusly like:

const data = await user()

thanks bro!