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

@@ -17,6 +17,6 @@ indent_style = tab
indent_size = 4 indent_size = 4
# Matches the exact files either package.json or .travis.yml # Matches the exact files either package.json or .travis.yml
[{package.json}] [{package.json,serverless.yml}]
indent_style = space indent_style = space
indent_size = 2 indent_size = 2

View File

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

View File

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

View File

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

View File

@@ -43,10 +43,14 @@ const register = async (req, res, next) => {
* @param {*} res * @param {*} res
* @param {*} next * @param {*} next
*/ */
const login = async (req, res) => { const login = async (req, res, next) => {
let user; let user;
try { user = await users.getByEmail(req.body.email); } try {
catch (error) { return done(error, null); } user = await users.getByEmail(req.body.email);
} catch (error) {
console.log(error);
return next(error, null);
}
if (!user) { if (!user) {
return res.status(404).send({ error: `Authentication failed. User not found.` }); 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 = {}) => { const register = async (user = {}) => {
// Validate // Validate
if (!user.email) throw new Error(`"email" is required`); if (!user.email) {
throw new Error(`"email" is required`);
}
if (!user.password) { if (!user.password) {
throw new Error(`"password" is required`); throw new Error(`"password" is required`);
} }
@@ -121,10 +123,18 @@ const getById = async (id) => {
const convertToPublicFormat = (user = {}) => { const convertToPublicFormat = (user = {}) => {
user.email = user.hk || null; user.email = user.hk || null;
user.id = user.sk2 || null; user.id = user.sk2 || null;
if (user.hk) delete user.hk; if (user.hk) {
if (user.sk) delete user.sk; delete user.hk;
if (user.sk2) delete user.sk2; }
if (user.password) delete user.password; if (user.sk) {
delete user.sk;
}
if (user.sk2) {
delete user.sk2;
}
if (user.password) {
delete user.password;
}
return user; return user;
}; };