Closed vukadinFE closed 2 years ago
Thanks @ejez, I saw it already but the thing I was looking for was setLink
method on apolloClient
instance.
I hoped that there is some super simple way for updating token via vuex: 'this.$apolloClient.updateHeaders()' :D
However I'll leave my implementation so if someone is searching for the same thing can use it:
//store/auth/actions.js
import { firebaseAuth, firebaseDb } from '../../boot/firebase';
import { createHttpLink } from '@apollo/client/core';
import { apolloClient } from 'src/boot/apollo';
import { defaultApolloOptions } from 'src/apollo';
export function authInit({ commit, dispatch, rootState }) {
firebaseAuth.onAuthStateChanged(async user => {
if (user) {
const token = await user.getIdToken();
apolloClient.setLink(createHttpLink({
...defaultApolloOptions,
headers: {
authorization: token
}
}))
}
})
}
Hi
I am using 2.0.0-beta.3 version and I wonder is there a simple way to update
apolloClient
options.Particularly, I have
onAuthStateChanges
firebase listener placed invuex
action and from there I would like to updateauthorization
header option.Thanks