Skip to content

Commit

Permalink
Update default otp
Browse files Browse the repository at this point in the history
  • Loading branch information
denizyesilirmak committed Nov 17, 2023
1 parent 8a04fcd commit 372414f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/routes/auth/auth.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,40 @@ router.post('/login/email/otp', async (req: Request, res: Response) => {

//otp found
//check otp
if (otp.otp !== req.body.otp || otp.otp !== '1234') {
if (otp.otp !== req.body.otp) {
return res.status(400).json({
success: false,
message: 'Otp is invalid.',
});
}

if (req.body.otp === '1234') {
//otp is valid, generate token and let user login
const user = await userModel.findOne({
email: req.body.email,
});

if (!user) {
return res.status(400).json(RESPONSE_ERRORS.USER_NOT_FOUND);
}

const data = {
email: req.body.email,
id: user._id,
};

const token = generateToken(data);

return res.json({
success: true,
message: 'Login successful.',
data: {
token,
email: req.body.email,
},
});
}

//otp is valid, generate token and let user login
const user = await userModel.findOne({
email: req.body.email,
Expand Down

0 comments on commit 372414f

Please sign in to comment.