passive-yellow
passive-yellow15mo ago

Redirect to login after session is invalid

Hi all, I'm trying to add a global error handler for invalid session replied from server. But I can find anywhere to do this. I have tried add check in authProvider, but it will call server api every page change Can someone help out. Thank you
2 Replies
kapa.ai
kapa.ai15mo ago
Hey @Junior Chen! I'm the kapa.ai support bot. I've searched through the docs to try to answer your question. :wave: ---------------------- It looks like you're trying to redirect the user to the login page when the session is invalid. You can do this by using the checkAuth method of the authProvider in the useCheckError hook. The checkAuth method should reject the Promise with an object that has a redirectPath property. Here's an example of how to do this:
const authProvider: AuthProvider = {
...
checkAuth: () => {
...
return Promise.reject({
redirectPath: "/login",
});
}
}
const authProvider: AuthProvider = {
...
checkAuth: () => {
...
return Promise.reject({
redirectPath: "/login",
});
}
}
For more information, please refer to the useCheckError documentation (https://refine.dev/docs/api-reference/core/hooks/auth/useCheckError). ----------------------
kapa.ai
kapa.ai15mo ago
<@1084864272280080505> kapa.ai is still learning and improving, please let us how it did by reacting below