I have Auth0 working effectively in my React app. Now, I am trying to track down edge cases to recover/respond when users hit errors. I see that useAuth0
returns an error. But I don’t see a list of the potential errors it can return or recommendations for how to respond to the different errors.
Is a list of the possible errors. And is there guidance for handling errors returned from useAuth0
?
Here is what I have:
import {useAuth0} from "@auth0/auth0-react";
export const onAuthError = async (error: Error, isAuthenticated: boolean, logout: (options?: LogoutOptions) => Promise<void>) => {
errorService.notify(error); //This is my error tracking. (We use Bugsnag)
localStorage.clear();
//log error to my error service
if (isAuthenticated) {
await logout();
}
if (window.location.pathname !== "/login") {
window.location.href = "/login";
}
};
const MyApp = () => {
const {isAuthenticated, getAccessTokenSilently, user, isLoading, error, logout} = useAuth0();
useEffect(() => {
if (error) {
onAuthError(error, isAuthenticated, logout);
}
}, [error]);
};
Same question is on StackOverflow: reactjs - How to recover from Auth0 Errors - Stack Overflow