Skip to content

Commit

Permalink
feat: implement simple spam protection
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbrusegard committed Jan 29, 2025
1 parent f9349cf commit 5726b4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/actions/sendEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const rateLimiter = new RateLimiter<string>(5, 120);

async function sendEmail(_: FormState, formData: FormData): Promise<FormState> {
try {
const honeypot = formData.get('website') as string;
if (honeypot) {
return { success: true, message: 'Thank you for your message' };
}

const headerStore = headers();
const clientIp =
headerStore.get('X-Real-IP') ??
Expand Down
8 changes: 8 additions & 0 deletions src/components/sections/contact/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ function ContactSection() {
Contact.
</h2>
<form className='mt-12 flex flex-col gap-8' action={formAction}>
<input
type='text'
name='website'
className='absolute left-[-9999px] hidden'
tabIndex={-1}
autoComplete='off'
aria-hidden='true'
/>
<label className='flex flex-col'>
<span className='mb-4 font-medium'>Your Name</span>
<input
Expand Down

0 comments on commit 5726b4f

Please sign in to comment.