Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OTP and makeAdmin/Client routes #3

Merged
merged 11 commits into from
Dec 16, 2024
Merged

Added OTP and makeAdmin/Client routes #3

merged 11 commits into from
Dec 16, 2024

Conversation

A-nirvana
Copy link
Collaborator

No description provided.

Copy link

netlify bot commented Oct 30, 2024

Deploy Preview for currenci-ecell ready!

Name Link
🔨 Latest commit f22176c
🔍 Latest deploy log https://app.netlify.com/sites/currenci-ecell/deploys/67324bd42f08500008863ca6
😎 Deploy Preview https://deploy-preview-3--currenci-ecell.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 86
Accessibility: 97
Best Practices: 92
SEO: 100
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

if (!user) {
return false;
}
const isReqAdmin = user.role === "admin" || "superadmin";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to const isReqAdmin = user.role === "admin" || user.role === "superadmin";
Your current code give only truthy value . Find out why ?


const token = authHeader.split(" ")[1];
try {
const decoded = jwt.verify(token, JWT_SECRET);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling for cases where jwt.verify fails due to expired or invalid tokens

import OtpModel from "../model/OTP";

export async function verifyOtp(email: string, otp: number) {
const OTPData = await OtpModel.findOne({ email });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling for the findOne query in case the database fails or the connection is lost.

}

const { pathname } = req.nextUrl;
const id = pathname.split("/").pop();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider checking if id is a valid MongoDB ObjectID to prevent errors.

}

const { pathname } = req.nextUrl;
const id = pathname.split("/").pop();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider checking if id is a valid MongoDB ObjectID to prevent errors.

);
}

const otp = Math.floor(100000 + Math.random() * 900000).toString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Strong OTP generation Libraries, as Math.random() can be predictable.

}

const otp = Math.floor(100000 + Math.random() * 900000).toString();
console.log(`Generated OTP for ${email}: ${otp}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove logging to maintain security

await dbConnect();
try {
const { username, email, password } = await req.json();
const { username, email, password, otp } = await req.json();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add validation to check if the password meets specific strength criteria before hashing it.

@@ -0,0 +1,29 @@
import nodemailer from "nodemailer";

const transporter = nodemailer.createTransport({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling for transporter.sendMail to capture cases where the email server might be down.

html,
};

transporter.sendMail(mailOptions, (error, info) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling for transporter.sendMail to capture cases where the email server might be down.

Copy link
Collaborator

@dheeraj1922d dheeraj1922d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolve highlighted issues

@Ruler45 Ruler45 merged commit 0685dfd into dev Dec 16, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants