diff --git a/.env.local b/.env.local index 6674896..a85fb44 100644 --- a/.env.local +++ b/.env.local @@ -6,4 +6,11 @@ NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=1038734866325 NEXT_PUBLIC_FIREBASE_APP_ID=1:1038734866325:web:22b09505809154eddb689c NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-5E30MTEKSN NEXT_PUBLIC_GOOGLE_CLOUD_VISION_API_KEY=AIzaSyCmO5hd0NfYV0yaePAva9PKhb4_IN1CdB8 -GOOGLE_APPLICATION_CREDENTIALS="D:\pantry tracker\vision-api-key.json" \ No newline at end of file +CLIENT_ID=52357093190-fi3tj2kgdn3e2dsit34n4fu8nn9paj3s.apps.googleusercontent.com +CLIENT_SECRET=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 +API_KEY=AIzaSyCmO5hd0NfYV0yaePAva9PKhb4_IN1CdB8 +EMAIL=burhancantcode@mythic-chalice-425119-r6.iam.gserviceaccount.com +UNIQUE_ID=103921260899615311592 +PROJECT_ID=mythic-chalice-425119-r6 +PRIVATE_KEY_ID=0c662e178d7e35ea1594f3432d2f9d97b989bbca +PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDSFm+rrDBGhGd3\n43KfN3erENOpqLttrM2denpOtNNNiNeaQwxs924wbIqfbsRda4gqlrAp4JIuSQnd\nLnpikGPcoJPaMgo7xeWz6LpBMoXsJHko5288szUL16wQV4svVtlLJXMlBDZ9WyYW\nhYsni9zGopdFGNLVpHCMGEia/jEzailRHxk6FKI5m8yxueriD2Nl9fk5Xh/Oyp7M\nkAHWOvVdfEBUm3li1HZEyKORIBFDaL0eXRrDPH08rveCzylYwXHo1cq5HvqvzMDa\nTtsedSrDXlpZ7sYlpS/BXX2xrnPxv8aZB3MBYX0kkt5T825QNIuI+X9cevRa8bh3\nHh6PU/QPAgMBAAECggEATxOa3OdnFGPp/jpifoOGS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GBAL6c9NER8NiUyTiU8U7G\nT1xeQgQTSTRA+BgI22T/wSNzkkgPoevA/z20mfzMfdS6JkamUop9eZ4yMiS56uvS\n5PsuYv38zT7MyIyFxxmkhi4eGNAHLyU6zIEqv7HhcCOAqynnulZM5I2j37zHgrK+\nOfRQB+3SkwhhLXTVt902f/BT\n-----END PRIVATE KEY-----\n" \ No newline at end of file diff --git a/components/AddProductForm.tsx b/components/AddProductForm.tsx index 44a2ea0..96519b5 100644 --- a/components/AddProductForm.tsx +++ b/components/AddProductForm.tsx @@ -1,9 +1,8 @@ import { useState } from 'react'; -import { TextField, Button, Box, Typography, CircularProgress, Dialog, DialogTitle, DialogContent, DialogActions, Snackbar, Alert } from '@mui/material'; +import { TextField, Button, Box, Typography, CircularProgress, Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material'; import { useProducts } from '../hooks/useProducts'; import ImageCapture from './ImageCapture'; import { scanProduct } from '../utils/visionUtils'; -import { useAuth } from '../hooks/useAuth'; const AddProductForm = () => { const [name, setName] = useState(''); @@ -13,9 +12,7 @@ const AddProductForm = () => { const [showConfirmation, setShowConfirmation] = useState(false); const [error, setError] = useState(null); const [potentialLabels, setPotentialLabels] = useState([]); - const [successOpen, setSuccessOpen] = useState(false); const { addProduct } = useProducts(); - const { user } = useAuth(); const handleImageCapture = async (imageData: string) => { console.log('Image data length:', imageData.length); @@ -38,7 +35,7 @@ const AddProductForm = () => { setQuantity(result.quantity.toString()); setPotentialLabels(result.allLabels || []); setShowConfirmation(true); - } catch (error) { + } catch (error: unknown) { console.error('Error scanning product:', error); setError('Failed to identify the product. Please try again or enter the details manually.'); } finally { @@ -52,31 +49,10 @@ const AddProductForm = () => { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - if (!user) { - setError('You must be logged in to add a product'); - return; - } - setLoading(true); - setError(null); - try { - await addProduct({ name, quantity: parseInt(quantity, 10) }); - console.log('Product added:', { name, quantity }); - setName(''); - setQuantity(''); - setSuccessOpen(true); - } catch (error) { - console.error('Error in handleSubmit:', error); - setError('Failed to add product'); - } finally { - setLoading(false); - } - }; - - const handleCloseSuccess = (event?: React.SyntheticEvent | Event, reason?: string) => { - if (reason === 'clickaway') { - return; - } - setSuccessOpen(false); + await addProduct({ name, quantity: parseInt(quantity, 10) }); + setName(''); + setQuantity(''); + setPrediction(null); }; return ( @@ -138,12 +114,6 @@ const AddProductForm = () => { - - - - Product added successfully! - - ); }; diff --git a/components/AuthModal.tsx b/components/AuthModal.tsx index 665a08f..2f6f03d 100644 --- a/components/AuthModal.tsx +++ b/components/AuthModal.tsx @@ -4,6 +4,7 @@ import { useAuth } from '../hooks/useAuth'; import { auth } from '../utils/firebaseConfig'; import { createUserWithEmailAndPassword, signInWithEmailAndPassword } from 'firebase/auth'; import { useRouter } from 'next/router'; +import { FirebaseError } from 'firebase/app'; interface AuthModalProps { buttonText?: string; @@ -19,7 +20,7 @@ const AuthModal: React.FC = ({ buttonText = "Sign In", fullWidth const { signIn, signUp } = useAuth(); const router = useRouter(); - const handleSubmit = async (e: React.FormEvent) => { + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); try { @@ -30,12 +31,22 @@ const AuthModal: React.FC = ({ buttonText = "Sign In", fullWidth } setOpen(false); router.push('/'); // Redirect to the main page - } catch (error) { + } catch (error: unknown) { console.error('Authentication error:', error); - setError(error.message); + if (error instanceof Error) { + setError(error.message); + } else { + setError('An unexpected error occurred'); + } } }; + // Helper function to extract error message + const getErrorMessage = (error: unknown): string => { + if (error instanceof Error) return error.message; + return String(error); + }; + return ( <>