Skip to content
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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

caotrungduc03
Copy link
Collaborator

E nộp btvn buổi 8 ạ

@caotrungduc03 caotrungduc03 changed the title added role to user.model, api login and api register, library bcrypt … BTVN8: added role to user.model, api login and api register, library bcrypt … May 15, 2023
@caotrungduc03 caotrungduc03 requested a review from hung279 May 20, 2023 02:34
throw err;
}

const token = await jwt.sign(
Copy link
Contributor

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é

Comment on lines 44 to 53
const {
avatar,
fullName,
dateOfBirth,
password,
studentCode,
className,
schoolYear,
clubYear
} = req.body;
Copy link
Contributor

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

Comment on lines +17 to +23
const user = await User.findById(userId);
if (!user) {
const err = new Error("User not found!");
err.status = 404;
throw err;
}

Copy link
Contributor

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.

Suggested change
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;

Comment on lines 29 to 31
{
expiresIn: '1h'
}

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é

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants