mirror of
https://github.com/bitbaum/botsmann.git
synced 2026-12-04 20:18:11 +01:00
fix: add API key header and improve form error handling
Co-Authored-By: G <butaeff@gmail.com>
This commit is contained in:
1 parent
5008326802
commit
f1b504a701
2 files changed
+9
-4
No files matched your search
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user