P粉1954022922023-08-29 21:23:43
I'm not sure what you've tried, but I know this will work. Of course, you can move onAuthStateChanged out of your store and it will still work. Remember, you have to use observers or computed props to track store.user and update the UI.
import { getAuth, onAuthStateChanged } from 'firebase/auth'; const auth = getAuth(); onAuthStateChanged(auth, async () => { const store = useStore(); store.setUser(); }); const useStore = defineStore('store', { state: () => ({ user: null }), actions: { setUser() { // Set user here // this.user = ... } } });