diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..5817666 --- /dev/null +++ b/.env.example @@ -0,0 +1,18 @@ +# MongoDB Keys +MONGODB_URI = + +#RESEND API Key And Email ID +RESEND_API_KEY = +RESEND_EMAIL_ID = + +ALLOWED_EMAIL_DOMAINS = + +ACCOUNTS_MODEL_NAME = + +BCRYPT_SALT_ROUNDS = + +JWT_TOKEN_VALUE = +EXPIRE_JWT_TOKEN = + +SECRET_KEY = +SECRET_IV = \ No newline at end of file diff --git a/src/app/api/forgotPassword/route.ts b/src/app/api/forgotPassword/route.ts index 9c40b1e..312477f 100644 --- a/src/app/api/forgotPassword/route.ts +++ b/src/app/api/forgotPassword/route.ts @@ -40,22 +40,4 @@ export async function PUT(request: NextRequest) { }, { status: 200 } ); -} - -export async function PATCH(request: NextRequest) { - - const userAgent = request.headers.get('user-agent'); - if (!userAgent) { return NextResponse.json({ message: "Internal Server Error", status: 500 }, { status: 200 }); } - const userIP = await fetchUserIP(); - - const { username, method } = await request.json(); - - const response = await resendOTP(username, method, userAgent, '', userIP); - if (!response) { return NextResponse.json({ message: "Internal Server Error", status: 500 }, { status: 200 }); } - - const { status, message } = response; - - if ([400, 401].includes(status)) { return NextResponse.json({ status, message }, { status: 200 }); } - - return NextResponse.json({ status, message }, { status: 200 }); } \ No newline at end of file diff --git a/src/app/api/resendOTP/route.ts b/src/app/api/resendOTP/route.ts new file mode 100644 index 0000000..bec613c --- /dev/null +++ b/src/app/api/resendOTP/route.ts @@ -0,0 +1,37 @@ +import { NextResponse, type NextRequest } from "next/server"; +import { resendOTP, signup, signUpVerify } from 'email-armor' +import { cookies } from 'next/headers' +import { fetchUserIP } from "@/app/utils/fetchUserIP"; + +console.clear(); + +export async function POST(request: NextRequest) { + + const userAgent = request.headers.get('user-agent'); + const userIP = await fetchUserIP(); + + const { userName, method } = await request.json(); + + const cookieStore = cookies(); + const id = cookieStore.get('id') || ""; + + //@ts-ignore + const response = await resendOTP(userName, method, userAgent, id.value, userIP); + + if (!response) { + return NextResponse.json( + { + message: "Internal Server Error", + status: 500 + }, + { status: 200 } + ); + } + + const { message, status } = response; + + return NextResponse.json( + { status, message }, + { status: 200 } + ); +} \ No newline at end of file diff --git a/src/app/api/signInAPI/route.ts b/src/app/api/signInAPI/route.ts index 7804768..63e5b81 100644 --- a/src/app/api/signInAPI/route.ts +++ b/src/app/api/signInAPI/route.ts @@ -47,27 +47,5 @@ export async function PUT(request: NextRequest) { //@ts-ignore cookies().set('token', signedJWTToken); - return NextResponse.json({ status, message }, { status: 200 }); -} - -export async function PATCH(request: NextRequest) { - - const userAgent = request.headers.get('user-agent'); - if (!userAgent) { return NextResponse.json({ message: "Internal Server Error", status: 500 }, { status: 200 }); } - const userIP = await fetchUserIP(); - - const { username, method } = await request.json(); - - const cookieStore = cookies() - const id = cookieStore.get('id') - if (!id) { return NextResponse.json({ message: "Internal Server Error", status: 500 }, { status: 200 }); } - - const response = await resendOTP(username, method, userAgent, id.value, userIP); - if (!response) { return NextResponse.json({ message: "Internal Server Error", status: 500 }, { status: 200 }); } - - const { status, message } = response; - - if ([400, 401].includes(status)) { return NextResponse.json({ status, message }, { status: 200 }); } - return NextResponse.json({ status, message }, { status: 200 }); } \ No newline at end of file diff --git a/src/app/api/signUpAPI/route.ts b/src/app/api/signUpAPI/route.ts index 46d2b29..79ae138 100644 --- a/src/app/api/signUpAPI/route.ts +++ b/src/app/api/signUpAPI/route.ts @@ -49,34 +49,6 @@ export async function PUT(request: NextRequest) { ); } - return NextResponse.json( - { status, message }, - { status: 200 } - ); -} - -export async function PATCH(request: NextRequest) { - - const userAgent = request.headers.get('user-agent'); - const userIP = await fetchUserIP(); - - const { userName } = await request.json(); - - //@ts-ignore - const response = await resendOTP(userName, 'newUserVerification', userAgent, '', userIP); - - if (!response) { - return NextResponse.json( - { - message: "Internal Server Error", - status: 500 - }, - { status: 200 } - ); - } - - const { message, status } = response; - return NextResponse.json( { status, message }, { status: 200 } diff --git a/src/app/forgotPassword/page.tsx b/src/app/forgotPassword/page.tsx index 599a602..5ec4c0a 100644 --- a/src/app/forgotPassword/page.tsx +++ b/src/app/forgotPassword/page.tsx @@ -61,7 +61,7 @@ const SignInPage = () => { const data = { username: formData.username, method: 'forgotPassword' }; try { - const { data: { message } } = await axios.patch('/api/forgotPassword', data); + const { data: { message } } = await axios.post('/api/resendOTP', data); setmessage(message); diff --git a/src/app/signIn/page.tsx b/src/app/signIn/page.tsx index c58b3dc..b2ad1ce 100644 --- a/src/app/signIn/page.tsx +++ b/src/app/signIn/page.tsx @@ -97,10 +97,10 @@ const SignInPage = () => { } const resendOTP = async () => { - const data = { username: formData.username, method: statusCode === 201 ? 'oldUserVerification' : 'newUserVerification' }; + const data = { userName: formData.username, method: statusCode === 201 ? 'oldUserVerification' : 'newUserVerification' }; try { - const { data: { message } } = await axios.patch('/api/signInAPI', data); + const { data: { message } } = await axios.post('/api/resendOTP', data); setmessage(message); diff --git a/src/app/signUp/page.tsx b/src/app/signUp/page.tsx index 92324de..5dc36ec 100644 --- a/src/app/signUp/page.tsx +++ b/src/app/signUp/page.tsx @@ -98,8 +98,11 @@ const SignUpPage = () => { } const resendOTP = async () => { + + const data = { userName: formData.userName, method: 'newUserVerification' } + try { - const { data: { message } } = await axios.patch('/api/signUpAPI', { userName: formData.userName }); + const { data: { message } } = await axios.post('/api/resendOTP', data); setmessage(message);