import React from 'react'; import { GoogleLogin, GoogleOAuthProvider } from '@react-oauth/google'; import { Link, useNavigate } from 'react-router-dom'; const CLIENT_ID = "532143017111-4eqtlp0oejqaovj6rf5l1ergvhrp4vao.apps.googleusercontent.com"; const LoginFormContent: React.FC = () => { const navigate = useNavigate(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); // Приведение типов для получения значений инпутов const emailElement = document.getElementById('email') as HTMLInputElement | null; const passwordElement = document.getElementById('password') as HTMLInputElement | null; if (!emailElement || !passwordElement) { console.error('Один или несколько инпутов отсутствуют'); return; } const email = emailElement.value; const password = passwordElement.value; try { const response = await fetch('http://localhost:5000/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }), }); const data = await response.json(); if (response.ok) { console.log('Login successful:', data.message); const loggedInUser = { name: data.user.name, email: data.user.email, picture: data.user.picture || 'https://via.placeholder.com/150', }; localStorage.setItem('user', JSON.stringify(loggedInUser)); navigate('/dashboard'); } else { console.error('Ошибка:', data.error); } } catch (error) { console.error('Ошибка при входе:', error); } }; const handleGoogleLoginSuccess = async (response: any) => { try { const res = await fetch('http://localhost:5000/api/verify', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token: response.credential }), }); const data = await res.json(); const loggedInUser = { name: data.user.name, email: data.user.email, picture: data.user.picture || 'https://via.placeholder.com/150', }; localStorage.setItem('user', JSON.stringify(loggedInUser)); navigate('/dashboard'); } catch (error) { console.error('Ошибка верификации токена:', error); } }; const handleGoogleLoginError = (error: any) => { console.error('Ошибка аутентификации через Google:', error); }; return (

Sign In

OR

Don't have an account?{' '} Sign Up

); }; const LoginForm: React.FC = () => { return ( ); }; export default LoginForm;