login now checks against db and attaches user data to req.user

This commit is contained in:
Mikayla Dobson
2022-09-28 17:16:51 -05:00
parent 404bc27c57
commit da4fed8e1e
7 changed files with 55 additions and 27 deletions

View File

@@ -37,16 +37,9 @@ module.exports = class AuthService {
try {
const user = await UserInstance.findOneByEmail(email);
if (!user) throw createError(401, 'Incorrect email or password');
// const match = bcrypt.compare(user.password, password, (result, err) => {
// if (err) throw err;
// return result;
// })
// console.log(match);
// if (!match) throw createError(401, 'Incorrect email or password');
console.log(user.password);
const match = bcrypt.compare(password, user.password).then((result) => console.log(result));
if (!match) throw createError(401, 'Incorrect email or password');
return user;
} catch(e) {
throw createError(500, e);

View File

@@ -15,11 +15,15 @@ module.exports = class CartService {
async getCart(userid) {
const result = await CartInstance.findOneByUserId(userid);
if (!result) throw createError(404, "Cart not found");
console.log(result.id);
return result;
}
async addItem(userid, item) {
async addItem(userid, itemid) {
const cart = await CartInstance.findOneByUserId(userid);
const newItem = await CartProductInstance.create(item);
const newItem = await CartProductInstance.create(itemid);
}
async removeItem(userid, item) {