Error: Invalid state when calling handleRedirectCallback on React App

This is my final solution. I am not sure how to raise as a github issue.

export default function Auth0Callback() {
	const navigate = useNavigate();
	const shouldRedirect = useRef(true);

	useEffect(() => {
		if (shouldRedirect.current) {
			shouldRedirect.current = false;

			(async () => {
				try {
					await handleRedirectCallback();
					navigate(localStorage.getItem('redirectTo') || '/');
				} catch (e) {
					navigate('/500');
				}
			})();
		}
	}, [navigate]);

	return (
		<SpinnerContainer>
			<Spinner />
		</SpinnerContainer>
	);
}

1 Like