Enforce more lint rules.

This commit is contained in:
2020-11-01 20:54:26 -06:00
parent 33aaddad9c
commit b758b85b15
6 changed files with 40 additions and 14 deletions

View File

@@ -28,6 +28,12 @@
"indent": [
"error",
"tab"
],
"curly": [
"error"
],
"brace-style": [
"error"
]
}
}

View File

@@ -9,8 +9,11 @@ const {
* Configure Passport
*/
try { require(`./config/passport`)(passport); }
catch (error) { console.log(error); }
try {
require(`./config/passport`)(passport);
} catch (error) {
console.log(error);
}
/**
* Configure Express.js Middleware

View File

@@ -14,13 +14,16 @@ module.exports = (passport) => {
passport.use(new StrategyJWT(options, async (jwtPayload, done) => {
let user;
try { user = await users.getById(jwtPayload.id); }
catch (error) {
try {
user = await users.getById(jwtPayload.id);
} catch (error) {
console.log(error);
return done(error, null);
}
if (!user) { return done(null, false); }
if (!user) {
return done(null, false);
}
return done(null, user);
}));
};

View File

@@ -43,10 +43,14 @@ const register = async (req, res, next) => {
* @param {*} res
* @param {*} next
*/
const login = async (req, res) => {
const login = async (req, res, next) => {
let user;
try { user = await users.getByEmail(req.body.email); }
catch (error) { return done(error, null); }
try {
user = await users.getByEmail(req.body.email);
} catch (error) {
console.log(error);
return next(error, null);
}
if (!user) {
return res.status(404).send({ error: `Authentication failed. User not found.` });

View File

@@ -19,7 +19,9 @@ const dynamodb = new AWS.DynamoDB.DocumentClient({
const register = async (user = {}) => {
// Validate
if (!user.email) throw new Error(`"email" is required`);
if (!user.email) {
throw new Error(`"email" is required`);
}
if (!user.password) {
throw new Error(`"password" is required`);
}
@@ -121,10 +123,18 @@ const getById = async (id) => {
const convertToPublicFormat = (user = {}) => {
user.email = user.hk || null;
user.id = user.sk2 || null;
if (user.hk) delete user.hk;
if (user.sk) delete user.sk;
if (user.sk2) delete user.sk2;
if (user.password) delete user.password;
if (user.hk) {
delete user.hk;
}
if (user.sk) {
delete user.sk;
}
if (user.sk2) {
delete user.sk2;
}
if (user.password) {
delete user.password;
}
return user;
};