Handling waiting for authentication before attempting query #1613
Unanswered
tomchambers2
asked this question in
Q&A
Replies: 2 comments
-
@tomchambers2 You might not recall, since it's been 3 years, but I'm new to the library have the same question now. Do you remember how you solved it? |
Beta Was this translation helpful? Give feedback.
0 replies
-
This feels more like a router issue than RTK. const Router = () => {
const isAuthenticated = useSelector(selectIsAuthenticated);
return isAuthenticated ? <AuthRouters /> : <LoginNavigator />;
}; Now you can expect that token is set on routers under AuthRouters |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This feels like a pretty common pattern, but I can't figure it out. I want to wait for the user to be authenticated before trying to make a request that errors because the JWT isn't present.
I can do
but this means having that skipToken logic in every hook call (which is a lot because we are using the user details in a lot of places).
I looked at altering the baseQuery to delay until the token is there, but it can only respond with data or error. The query also doesn't seem to be able to handle waiting.
Is there a way I can move this check to somewhere else and not have the request fire at all until the token exists?
Beta Was this translation helpful? Give feedback.
All reactions