Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Capta1nRaj committed Apr 7, 2024
1 parent 9e73fa1 commit e07b20c
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 72 deletions.
18 changes: 18 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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 =
18 changes: 0 additions & 18 deletions src/app/api/forgotPassword/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
37 changes: 37 additions & 0 deletions src/app/api/resendOTP/route.ts
Original file line number Diff line number Diff line change
@@ -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 }
);
}
22 changes: 0 additions & 22 deletions src/app/api/signInAPI/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
28 changes: 0 additions & 28 deletions src/app/api/signUpAPI/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/app/forgotPassword/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/app/signIn/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion src/app/signUp/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e07b20c

Please sign in to comment.