Files
hMarket/frontend/src/components/Auth/GoogleCallback.tsx
2026-02-03 01:22:08 +03:00

61 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React, { useEffect } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { Box, CircularProgress, Typography } from '@mui/material';
import { useAuth } from '../../contexts/AuthContext';
import toast from 'react-hot-toast';
const GoogleCallback: React.FC = () => {
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const { handleGoogleCallback } = useAuth();
useEffect(() => {
const handleCallback = async () => {
const token = searchParams.get('token');
const error = searchParams.get('error');
if (error) {
toast.error('Google ile giriş yapılamadı: ' + error);
navigate('/login');
return;
}
if (token) {
try {
await handleGoogleCallback(token);
toast.success('Google ile başarıyla giriş yapıldı!');
navigate('/dashboard');
} catch (error) {
console.error('Google callback error:', error);
toast.error('Giriş işlemi sırasında bir hata oluştu');
navigate('/login');
}
} else {
toast.error('Geçersiz callback');
navigate('/login');
}
};
handleCallback();
}, [searchParams, navigate, handleGoogleCallback]);
return (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
minHeight: '100vh',
gap: 2,
}}
>
<CircularProgress size={60} />
<Typography variant="h6" color="text.secondary">
Google ile giriş yapılıyor...
</Typography>
</Box>
);
};
export default GoogleCallback;