Just started with nuxtjs and using the Nuxt firebase library for firebase integration. After a successful login, I'm redirecting the user to the "/member/desk" route. However, if I refresh the page on that particular route, it redirects me back to "/auth/signin". This happens because in the "middleware/auth.js" file, I am not receiving the value of app.$fire.auth.currentUser
as null
.
I tried searching online for a solution but couldn't find any reliable information. Any help would be appreciated.
Here are the relevant sections of my files:
- nuxt.config.js
[
'@nuxtjs/firebase',
{
config: {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
},
services: {
auth: {
persistence: 'local', // default
initialize: {
onAuthStateChangedAction: 'onAuthStateChangedAction',
subscribeManually: false
},
ssr: false
}
}
}
]
- store/index.js
// Code for store/index.js goes here...
- middleware/auth.js
// Code for middleware/auth.js goes here...
- pages/index.js
// Code for pages/index.js goes here...
https://i.sstatic.net/aGAgG.png
--- UPDATE ---
Recently implemented "Firebase Auth with SSR" and was able to partially resolve the issue. Now, when I refresh normally on the "/member/desk" route, it works fine (stays on the same page). However, when I do a HARD RELOAD, it redirects to the "/auth/signin" route.
I suspect it has something to do with the implementation of the Service Worker. On HARD RELOAD, all cached data is cleared and the Service Worker restarts.
If anyone can provide some clarity on this, it would be greatly appreciated!