Update the status within the client could it be fine or is it horrible? #1114
Answered
by
kitten
albertcito
asked this question in
Q&A
-
const StartApp = () => {
const { setUser, ...props } = useUser();
const client = useRef(createClient({
url: `${constants.urlServer}/graphql/public`,
fetchOptions: () => {
const token = localStorage.getItem('accessToken');
return {
headers: { authorization: token ? `Bearer ${token}` : '' },
withCredentials: true,
};
},
exchanges: [
dedupExchange,
cacheExchange,
retryExchange({
retryIf: (error) => {
if (error.response.status === 403) { setUser(); }
return false;
},
}),
fetchExchange,
],
})).current;
return (
<UserContext.Provider value={{ ...props, setUser }}>
<Provider value={client}>
<GlobalStatus />
</Provider>
</UserContext.Provider>
);
}; |
Beta Was this translation helpful? Give feedback.
Answered by
kitten
Nov 3, 2020
Replies: 1 comment
-
Depending on how you're using the credentials this will be completely fine. This obviously can't quite be a complete example but there's some assymmetry between your authorisation management in If you already have a singleton that manages the user or a context object, you could instead investigate using the authorisation exchange instead: https://formidable.com/open-source/urql/docs/advanced/authentication/ |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kitten
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Depending on how you're using the credentials this will be completely fine. This obviously can't quite be a complete example but there's some assymmetry between your authorisation management in
useUser
and the token being retrieved from local storage.If you already have a singleton that manages the user or a context object, you could instead investigate using the authorisation exchange instead: https://formidable.com/open-source/urql/docs/advanced/authentication/