Skip to content

Commit

Permalink
Change in the OAuthcallback
Browse files Browse the repository at this point in the history
  • Loading branch information
VenEleni committed Aug 26, 2024
1 parent 74c6bca commit 4029f79
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions client/src/components/OAuthCallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,25 @@ function OAuthCallback() {
const location = useLocation();

useEffect(() => {
const handleCallback = async () => {
const urlParams = new URLSearchParams(location.search);
const token = urlParams.get('token');

if (token) {
try {
await dispatch(handleOAuthCallback(token));
// Redirect to the homepage
const urlParams = new URLSearchParams(location.search);
const token = urlParams.get('token');

if (token) {
dispatch(handleOAuthCallback(token))
.then(() => {
navigate('/');
} catch (error) {
console.error('Error processing OAuth callback:', error);
navigate('/login', { state: { error: 'Failed to process login. Please try again.' } });
}
} else {
console.error('No token received from OAuth login');
navigate('/login', { state: { error: 'No authentication token received. Please try again.' } });
}
};

handleCallback();
})
.catch((error) => {
console.error('OAuth callback error:', error);
navigate('/login', { state: { error: 'Authentication failed. Please try again.' } });
});
} else {
console.error('No token received in OAuth callback');
navigate('/login', { state: { error: 'No authentication token received. Please try again.' } });
}
}, [dispatch, navigate, location]);

return <div>Processing login...</div>;
return <div>Processing authentication...</div>;
}

export default OAuthCallback;

0 comments on commit 4029f79

Please sign in to comment.