-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BTVN8: added role to user.model, api login and api register, library bcrypt … #46
base: main
Are you sure you want to change the base?
Conversation
src/controllers/auth.controller.js
Outdated
throw err; | ||
} | ||
|
||
const token = await jwt.sign( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
method sign này nó k trả về promise đâu nên mình k cần await nhé
src/controllers/auth.controller.js
Outdated
const { | ||
avatar, | ||
fullName, | ||
dateOfBirth, | ||
password, | ||
studentCode, | ||
className, | ||
schoolYear, | ||
clubYear | ||
} = req.body; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avatar
anh nghĩ k nên để trong phần đăng ký nhé. Đăng ký mình chỉ đưa những trường cần thiết thôi
const user = await User.findById(userId); | ||
if (!user) { | ||
const err = new Error("User not found!"); | ||
err.status = 404; | ||
throw err; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
em thêm cho anh nếu mà user tồn tại thì mình sẽ gán nó vào req để sử dụng ở các hàm sau.
const user = await User.findById(userId); | |
if (!user) { | |
const err = new Error("User not found!"); | |
err.status = 404; | |
throw err; | |
} | |
const user = await User.findById(userId); | |
if (!user) { | |
const err = new Error("User not found!"); | |
err.status = 404; | |
throw err; | |
} | |
req.user = user; | |
Co-authored-by: Tan Hung(hoon) <[email protected]>
src/controllers/auth.controller.js
Outdated
{ | ||
expiresIn: '1h' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
không hard code ở thời gian sống của token, đặt biến trong .env và sử dụng nhé
E nộp btvn buổi 8 ạ