Skip to content

Feature/ds 20: Auth API#16

Open
phamhoangvu2k7 wants to merge 4 commits into
devfrom
feat/DS-20
Open

Feature/ds 20: Auth API#16
phamhoangvu2k7 wants to merge 4 commits into
devfrom
feat/DS-20

Conversation

@phamhoangvu2k7
Copy link
Copy Markdown
Collaborator

No description provided.

This comment was marked as spam.

login = async req => {
login = async (req, res) => {
const data = await this.service.login(LoginDto(req.body));
res.cookie('access_token', data.access_token, { ...cookieOptions, maxAge: ACCESS_TOKEN_MAX_AGE });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

chổ res cookie access refresh lặp lại nhiều lần nè , em thêm hàm để xử lý phần res này

};

logout = async (req, res) => {
const data = await this.service.logout(LogoutDto(req.body));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Logout thì ko gửi req.body á em . Logout dựa vào refresh token trong cookie hoặc user context

sameSite: 'lax',
};

const ACCESS_TOKEN_MAX_AGE = 24 * 60 * 60 * 1000; // 1 day
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mấy const này đưa vào file config nha , đừng để ở controller


ApiDocument.addModel('LogoutDto',
{
refresh_token: SwaggerDocument.ApiProperty({ type: 'string' }),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hình như em dùng cookie-based rồi thì logout dto này ko cần nữa


refresh = async req => {
refresh = async (req, res) => {
const data = await this.service.refresh(RefreshDto(req.body));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

em đang sài cookie thì lấy từ req.cookies.refresh_token nha

}

return {
message: 'Dang xuat thanh cong.',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Message tiếng anh nha

Comment thread backend/src/core/modules/auth/service/auth.service.js
Comment thread backend/src/core/modules/auth/service/auth.service.js Outdated
Comment thread backend/plan/auth_api_guide.md Outdated
// 4. Tao cap token moi (access + refresh)
// 5. Tra ve { access_token, refresh_token }
async refresh(refreshDto) {
const tokenRecord = await this.refreshTokenRepository.findValidToken(refreshDto.refresh_token);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

refreshDto.refresh_token nên check rỗng trước

Comment thread backend/plan/auth_api_guide.md Outdated
}

const accessToken = this.jwtService.sign(JwtPayload({ id: user.id, roles: [user.role] }));
const refreshToken = await this.#createRefreshToken(user.id);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

trong #createRefreshToken nên lưu nha hash token tránh lưu raw

This comment was marked as duplicate.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
d-shiftify Error Error May 17, 2026 2:28am

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.

3 participants