Skip to content

Conversation

@fletchulence
Copy link

No description provided.

return next({ status: 401, message: 'Token required'})
}
jwt.verify(token, JWT_SECRET, (err, decode)=>{
if(err){
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesnt match above white space

*/
const { username } = req.body
try{
const dbUsername = await User.findBy({ username })
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbUsername actually is a collection == dbUsers

returns an array

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generalize

}
*/
let { role_name } = req.body
// let role_name = role_name.trim()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take out the comments as normal --- delete it!

*/
let { role_name } = req.body
// let role_name = role_name.trim()
if( !role_name || role_name.trim() === undefined ){
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after || will never be called

next()
} else {
if ( role_name.trim() === 'admin'){
return next({ status: 422, message: 'Role name can not be admin'})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return is not necessary if you have "else/else if" right after...
change one or the other

@@ -1,8 +1,12 @@
const router = require("express").Router();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

be consistent with semicolons !!

const tokenBuilder = require('./helpers')
const { checkUsernameExists, validateRoleName } = require('./auth-middleware');
const { JWT_SECRET } = require("../secrets"); // use this secret!
const { BCRYPT_ROUNDS } = require("../secrets"); // use this secret!
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the comment be a lifesaver here??

if yes, leave in
if not, take out

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no misleading comments

const hash = bcrypt.hashSync(password, BCRYPT_ROUNDS)
const role = req.role_name
try {
const newUser = await User.add({ username, password: hash, role_name: role })
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep lines under 100 at least ((maybe 80 if possible))

*/

try {
let user = req.user
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could have destructured

return db('users as u')
.leftJoin('roles as r', 'r.role_id', 'u.role_id')
.select('u.*', 'r.*')
.where(filter).first()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only finding the first in the array

"knex": "^0.95.14",
"sqlite3": "^5.0.2"
"jsonwebtoken": "^8.5.1",
"knex": "^1.0.1"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding risk by doing this -- might be increasing the possibility of errs

only if you need to use the new version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant