Fix bugs from refactor!
This commit is contained in:
@@ -18,5 +18,5 @@ 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,serverless.yml}]
|
[{package.json,serverless.yml}]
|
||||||
indent_style = space
|
indent_style = tab
|
||||||
indent_size = 2
|
indent_size = 4
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ const ExtractJWT = require(`passport-jwt`).ExtractJwt;
|
|||||||
const { users } = require(`../models`);
|
const { users } = require(`../models`);
|
||||||
|
|
||||||
module.exports = (passport) => {
|
module.exports = (passport) => {
|
||||||
|
|
||||||
const options = {};
|
const options = {};
|
||||||
options.jwtFromRequest = ExtractJWT.fromAuthHeaderAsBearerToken();
|
options.jwtFromRequest = ExtractJWT.fromAuthHeaderAsBearerToken();
|
||||||
options.secretOrKey = process.env.tokenSecret;
|
options.secretOrKey = process.env.tokenSecret;
|
||||||
@@ -24,6 +23,6 @@ module.exports = (passport) => {
|
|||||||
if (!user) {
|
if (!user) {
|
||||||
return done(null, false);
|
return done(null, false);
|
||||||
}
|
}
|
||||||
return done(null, user);
|
return done(null, users.convertToPublicFormat(user));
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const register = async (req, res, next) => {
|
|||||||
return next(error, null);
|
return next(error, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = jwt.sign(user, process.env.tokenSecret, {
|
const token = jwt.sign(users.convertToPublicFormat(user), process.env.tokenSecret, {
|
||||||
expiresIn: 604800 // 1 week
|
expiresIn: 604800 // 1 week
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ const login = async (req, res, next) => {
|
|||||||
return res.status(401).send({ error: `Authentication failed. Wrong password.` });
|
return res.status(401).send({ error: `Authentication failed. Wrong password.` });
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = jwt.sign(user, process.env.tokenSecret, {
|
const token = jwt.sign(users.convertToPublicFormat(user), process.env.tokenSecret, {
|
||||||
expiresIn: 604800 // 1 week
|
expiresIn: 604800 // 1 week
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const register = async (user = {}) => {
|
|||||||
{
|
{
|
||||||
hk: user.email,
|
hk: user.email,
|
||||||
password: user.password,
|
password: user.password,
|
||||||
}).promise();
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,12 +51,9 @@ const getByEmail = async (email) => {
|
|||||||
throw new Error(`"${email}" is not a valid email address`);
|
throw new Error(`"${email}" is not a valid email address`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = await db.getByKey(email).promise();
|
let user = await db.getByKey(email);
|
||||||
|
|
||||||
user = user.Items && user.Items[0] ? user.Items[0] : null;
|
user = user.Items && user.Items[0] ? user.Items[0] : null;
|
||||||
if (user) {
|
|
||||||
user = convertToPublicFormat(user);
|
|
||||||
}
|
|
||||||
return user;
|
return user;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -70,12 +67,9 @@ const getById = async (id) => {
|
|||||||
throw new Error(`"id" is required`);
|
throw new Error(`"id" is required`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = await db.getById(`user`, id).promise();
|
let user = await db.getById(`user`, id);
|
||||||
|
|
||||||
user = user.Items && user.Items[0] ? user.Items[0] : null;
|
user = user.Items && user.Items[0] ? user.Items[0] : null;
|
||||||
if (user) {
|
|
||||||
user = convertToPublicFormat(user);
|
|
||||||
}
|
|
||||||
return user;
|
return user;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user