vuefire icon indicating copy to clipboard operation
vuefire copied to clipboard

Using auth.onAuthStateChanged() in default export

Open mewcrazy opened this issue 5 years ago • 3 comments

Hello,

I'm trying to delay the execution of my App until Firebase receives the Auth status before my "not logged in"-redirections take place. Afaik this is usually done with:

auth.onAuthStateChanged((user) => { new Vue() })

But in my current Vue setup my Vue instance get called in a total different way, which gives me a tough time.

// we should return factory for SSR (runInNewContext: false) export default context => { const store = createStore(context), router = createRouter(context); sync(store, router); return new Vue({ i18n, store, router, ...app }); };

I tried encapsulating new Vue to a const, and turn this constant inside the onAuthStateChanged function. Didn't work. Inside the export default neither. Around the return new Vue neither.

Can someone give me a hint? I already killed hours on this simple task :/

P.S. I'm working with SSR.

mewcrazy avatar Dec 31 '19 10:12 mewcrazy

This is not related to Vuefire, but I'm interested in adding it to the cookbook if anybody did Firebase authentication + SSR

posva avatar Dec 31 '19 11:12 posva

If needed I can deliver some source files. My SSR setup seems pretty complex.

mewcrazy avatar Dec 31 '19 11:12 mewcrazy

This article was quite helpful when I was implementing this earlier: https://dev.to/gautemeekolsen/vue-guard-routes-with-firebase-authentication-f4l

hacknug avatar Jan 20 '20 03:01 hacknug