File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010 "start" : " next start"
1111 },
1212 "dependencies" : {
13+ "@devmehq/email-validator-js" : " ^2.10.2" ,
1314 "@dnd-kit/core" : " ^6.3.1" ,
1415 "@dnd-kit/sortable" : " ^10.0.0" ,
1516 "@dnd-kit/utilities" : " ^3.2.2" ,
Original file line number Diff line number Diff line change 11import { NextResponse } from "next/server" ;
22import { appendEmailToSheet } from "@/lib/services/google-sheets" ;
3+ import { verifyEmail } from "@devmehq/email-validator-js" ;
34
45export async function POST ( req : Request ) {
56 try {
@@ -9,10 +10,25 @@ export async function POST(req: Request) {
910 return NextResponse . json ( { error : "Email is required" } , { status : 400 } ) ;
1011 }
1112
13+ const result = await verifyEmail ( {
14+ emailAddress : email ,
15+ verifyMx : true ,
16+ verifySmtp : false ,
17+ timeout : 4000
18+ } ) ;
19+
20+ if ( ! result . validFormat ) {
21+ return NextResponse . json ( { error : "Invalid email format" } , { status : 400 } ) ;
22+ }
23+
24+ if ( ! result . validMx ) {
25+ return NextResponse . json ( { error : "Email domain is invalid" } , { status : 400 } ) ;
26+ }
27+
1228 await appendEmailToSheet ( email ) ;
1329 return NextResponse . json ( { message : "Email added successfully" } ) ;
1430 } catch ( error ) {
1531 console . error ( "Error adding email:" , error ) ;
1632 return NextResponse . json ( { error : "Failed to add email" } , { status : 500 } ) ;
1733 }
18- }
34+ }
Original file line number Diff line number Diff line change @@ -25,8 +25,8 @@ export default function Footer() {
2525 }
2626 } , [ theme ] ) ;
2727 const handleSubscribe = async ( ) => {
28- if ( ! email ?. includes ( "@" ) ) {
29- toast . error ( "Please Enter A Valid Email ." ) ;
28+ if ( ! email . trim ( ) ) {
29+ toast . error ( "Please enter your email ." ) ;
3030 return ;
3131 }
3232
@@ -35,14 +35,16 @@ export default function Footer() {
3535 method : "POST" ,
3636 headers : { "Content-Type" : "application/json" } ,
3737 body : JSON . stringify ( { email } ) ,
38- } ) . then ( ( res ) => {
39- if ( ! res . ok ) throw new Error ( "Network response was not ok." ) ;
40- return res . json ( ) ;
38+ } )
39+ . then ( async ( res ) => {
40+ const data = await res . json ( ) ;
41+ if ( ! res . ok ) return Promise . reject ( data . error || "Something went wrong." ) ;
42+ return data ;
4143 } ) ,
4244 {
4345 loading : "Subscribing..." ,
4446 success : "You've Successfully Subscribed!" ,
45- error : "Something went wrong. Try again later." ,
47+ error : ( err : any ) => err ,
4648 } ,
4749 ) ;
4850
You can’t perform that action at this time.
0 commit comments