fix: add API key header and improve form error handling

Co-Authored-By: G <butaeff@gmail.com>
This commit is contained in:
Devin AIandcato committed 2025-02-11 00:09:29 +00:00
1 parent 5008326802
commit f1b504a701
2 files changed
+9 -4

No files matched your search

+1
View File
@@ -3,6 +3,7 @@ MONGODB_URI=mongodb://localhost:27017/botsmann
# API key for authentication
API_KEY=your-secure-api-key-here
NEXT_PUBLIC_API_KEY=your-secure-api-key-here
# Email Configuration
SENDGRID_API_KEY=your_sendgrid_api_key
+8 -4
View File
@@ -23,18 +23,22 @@ export default function ConsultationForm() {
const response = await fetch('/api/consultations', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
headers: {
'Content-Type': 'application/json',
'x-api-key': process.env.NEXT_PUBLIC_API_KEY || ''
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error('Submission failed');
const errorData = await response.json();
throw new Error(errorData.error || 'Submission failed');
}
reset();
setSubmitSuccess(true);
} catch (error) {
setSubmitError('Failed to submit form. Please try again.');
} catch (error: any) {
setSubmitError(error.message || 'Failed to submit form. Please try again.');
} finally {
setIsSubmitting(false);
}