With Vue Router you might want to guard some paths and redirect users to a signup page if they are not authenticated. I will show you how this is d...
For further actions, you may consider blocking this person and/or reporting abuse
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!
This is awesome! This is a major issue (I ended up thinking I will have to write my entire app in a single file to avoid that auth problem) and I am surprised I haven't found an elegant solution like that anywhere else on the web!
The next problem, I'm trying to fight it on github.com/tarkhil/authts is that RouterGuard does nothing on the first request to the router.
I have no idea what I could make wrong. But now it's 100% repeatable for me
Seems to be the most complete and elaborated example on the subject
Thank you! You've made my day!
Unfortunately, firebase.getCurrentUser = () requires something additional in TypeScript and I did not get answer yet
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:
I can confirm that this approach worked for me in TS. :-) Many thanks @gautemeekolsen for sharing this knowledge.
That just saved me from probably several hours of trying to figure out how to solve it, and I still wouldn't have done it as elegantly as that. :-) Thanks!
Me ajudou muito... algo simples e direto!!!
Parabéns!!!