Closed cifuentesmx closed 3 years ago
Hey @robertocifuentes
For me your code is working as expected. The service worker gets loaded and I can log out the authUser
in the mutation:
ON_AUTH_STATE_CHANGED_MUTATION(state, { authUser, claims }) {
console.log(authUser)
Returns:
Why do you expect axios to automatically include the Firebase token? I don't see where you add the Firebase token to the axios instance.
You can set authorization headers on Axios like so, I think you can do this on each request but also directly on the entire axios instance in ON_AUTH_STATE_CHANGED_MUTATION, so you only have to do it once.
But if there is an issue please refer to the axios repository.
Hope that helped,
br, Pascal
Made an example project for you here: https://github.com/lupas/nuxt-firebase-server-auth-demo
You can see the relevant code to add the authorization header to your axios instance here: https://github.com/lupas/nuxt-firebase-server-auth-demo/blob/master/packages/frontend/store/actions.js#L32
Version
@nuxtjs/firebase: ^7.3.0 firebase: ^8.2.2 nuxt: ^2.14.6
Reproduction Link
https://github.com/robertocifuentes/firebase-nuxt-ssr-issue
Steps to reproduce
What is Expected?
When a user is logged in, all
$axios
requests will contain the firebase token (managed by the/firebase-auth-sw.js
), so we can install a custom server which authenticates client requests trough Firebase admin SDK.What is actually happening?
Apparently the
firebase-auth-sw.js
is not getting installed thus theaxios
requests do not contains the firebase token.Is this an issue?
Even I've tried different workarounds, I didn't managed to solve it. I'm not sure this is an issue or a messed up configuration problem or just me not fully understanding some basic concept.
These are the headers of a request when running a production server, the cookies are empty: