Closed softglance closed 7 years ago
Did you use authMiddleware
with react-relay-network-layer
?
This middleware will take a token from the store for every request.
authMiddleware({
token: () => store.get('jwt'),
tokenRefreshPromise: (req) => {
console.log('[client.js] resolve token refresh', req);
return fetch('/jwt/refresh')
.then(res => res.json())
.then(json => {
const token = json.token;
store.set('jwt', token);
return token;
})
.catch(err => console.log('[client.js] ERROR can not refresh token', err));
},
}),
Thanks! It works, now the token is getting refreshed. After I login the old data from the relay store is loading. I tried using the this.props.relay.forceFectch() but still not getting the new data of logged in user.
I such case you should create a new Relay Environment and replace old one in Relay.Renderer. (parent component just replace prop environment
by the new instance)
https://facebook.github.io/relay/docs/api-reference-relay-renderer.html
The above comment was useful. Thanks!
Below is the code implemented. It works for a single user. when user login is switched the token is not getting refreshed for the new token received from server. .
On server side:
On client side:
On logout:
I also tried using react-relay-network-layer but facing same issue.