Add prettier to api

This commit is contained in:
2020-11-11 21:26:11 -06:00
parent 0193935d2d
commit 7706f525cf
11 changed files with 90 additions and 87 deletions

View File

@@ -2,4 +2,4 @@ const users = require(`./users`);
module.exports = {
users,
};
};

View File

@@ -27,13 +27,17 @@ const register = async (req, res, next) => {
return next(error, null);
}
const token = jwt.sign(users.convertToPublicFormat(user), process.env.tokenSecret, {
expiresIn: 604800 // 1 week
});
const token = jwt.sign(
users.convertToPublicFormat(user),
process.env.tokenSecret,
{
expiresIn: 604800, // 1 week
}
);
res.json({
message: `Authentication successful`,
token
token,
});
};
@@ -53,21 +57,29 @@ const login = async (req, res, next) => {
}
if (!user) {
return res.status(404).send({ error: `Authentication failed. User not found.` });
return res
.status(404)
.send({ error: `Authentication failed. User not found.` });
}
const isCorrect = comparePassword(req.body.password, user.password);
if (!isCorrect) {
return res.status(401).send({ error: `Authentication failed. Wrong password.` });
return res
.status(401)
.send({ error: `Authentication failed. Wrong password.` });
}
const token = jwt.sign(users.convertToPublicFormat(user), process.env.tokenSecret, {
expiresIn: 604800 // 1 week
});
const token = jwt.sign(
users.convertToPublicFormat(user),
process.env.tokenSecret,
{
expiresIn: 604800, // 1 week
}
);
res.json({
message: `Authentication successful`,
token
token,
});
};