File tree Expand file tree Collapse file tree 5 files changed +38
-7
lines changed Expand file tree Collapse file tree 5 files changed +38
-7
lines changed Original file line number Diff line number Diff line change @@ -28,4 +28,5 @@ type Params = {
2828 "/account/profile" : { } ;
2929 "/account/orders" : { } ;
3030 "/not-found" : { } ;
31+ "/verify-email" : { } ;
3132} ;
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export default [
2323 route ( "orders" , "./routes/account/orders/index.tsx" ) ,
2424 ] ) ,
2525 route ( "/not-found" , "./routes/not-found/index.tsx" ) ,
26+ route ( "/verify-email" , "./routes/verify-email/index.tsx" ) ,
2627 ] ,
2728 } ,
2829] satisfies RouteConfig ;
Original file line number Diff line number Diff line change 1+ import { verifyUniqueEmail } from "@/services/user.service" ;
2+
3+ import type { Route } from "./+types" ;
4+
5+ export async function loader ( { request } : Route . ActionArgs ) {
6+ const url = new URL ( request . url ) ;
7+ const email = url . searchParams . get ( "email" ) ;
8+
9+ if ( email ) {
10+ const response = await verifyUniqueEmail ( email ) ;
11+ return response ;
12+ }
13+ return false ;
14+ }
Original file line number Diff line number Diff line change 1- import { client } from "@/lib/utils" ;
2-
3- // Se mantiene para hacer la validación de correo electrónico en el registro del lado del cliente
41export async function findEmail ( email : string ) : Promise < boolean > {
5- const body = await client < boolean > ( "/users/findEmail" , {
6- body : { email } ,
7- } ) ;
2+ try {
3+ const response = await fetch (
4+ `/verify-email?email=${ encodeURIComponent ( email ) } `
5+ ) ;
6+
7+ if ( ! response . ok ) {
8+ throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
9+ }
810
9- return body ;
11+ const result = await response . json ( ) ;
12+ return result ;
13+ } catch ( error ) {
14+ console . error ( "Error verifying email:" , error ) ;
15+ return false ;
16+ }
1017}
Original file line number Diff line number Diff line change @@ -48,3 +48,11 @@ export async function getOrCreateUser(email: string): Promise<User> {
4848
4949 return existingUser ;
5050}
51+
52+ export async function verifyUniqueEmail ( email : string ) : Promise < boolean > {
53+ const user = await prisma . user . findUnique ( {
54+ where : { email } ,
55+ } ) ;
56+
57+ return user ? false : true ;
58+ }
You can’t perform that action at this time.
0 commit comments