Skip to content

Commit

Permalink
feat: add login via authToken cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunny-unik committed Dec 14, 2023
1 parent 2f93860 commit a01cc53
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,18 @@ export default class UserController {

static async loginUser(req, res) {
try {
const { email, name, password } = req.body;
const cookieData = jwt.decode(req.cookies.authToken);
const { email, name, password } = cookieData ? cookieData : req.body;
if (!email && !name && !password)
return res.status(400).send({ message: 'Invalid Credentials' });
const payload = await userSchema.findOne({
$or: [{ email: email }, { name: name }],
});
if (!payload) return res.status(404).send({ message: 'User not found' });

const match = await bcrypt.compare(password, payload.password);
const match =
password === payload.password ||
(await bcrypt.compare(password, payload.password));
if (match) {
const accessToken = jwt.sign(
JSON.parse(JSON.stringify(payload)),
Expand Down

0 comments on commit a01cc53

Please sign in to comment.