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

fix: auth 관련 api가 무조건 200 리턴 버그 #779

Merged
merged 17 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions backend/src/v1/routes/users.routes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Router } from 'express';
import { roleSet } from '~/v1/auth/auth.type';
import authValidate from '~/v1/auth/auth.validate';
import { create, getVersion, myupdate, search, update } from '~/v1/users/users.controller';
import { create, getVersion, myupdate, search, update, mydata } from '~/v1/users/users.controller';


export const path = '/users';
export const router = Router();
Expand Down Expand Up @@ -356,11 +357,60 @@ export const router = Router();
* type: string
* example: gshim.v1
*/
/**
* @openapi
* /api/users/me:
* get:
* description: 내 정보를 가져온다.
* tags:
* - users
* responses:
* '200':
* description: 내 정보를 반환한다.
* content:
* application/json:
* schema:
* properties:
* nickname:
* description: 에러코드
* type: string
* example: jimin
* intraId:
* description: 인트라 ID
* type: string
* example: 10035
* slack:
* description: slack 맴버 변수
* type: string
* example: "U02LNNDRC9F"
* role:
* description: 유저의 권한
* type: string
* example: 2
* penaltyEbdDate:
* description: 패널티가 끝나는 날
* type: string
* example: 2022-06-18
* overDueDay:
* description: 현재 연체된 날수
* type: string
* format: number
* example: 0
* reservations:
* description: 해당 유저의 예약 정보
* type: array
* example: []
* lendings:
* description: 해당 유저의 대출 정보
* type: array
* example: []
*/
router
.get('/search', search)
.get('/search', authValidate(roleSet.librarian), search)

Check failure

Code scanning / CodeQL

Missing rate limiting

This route handler performs [authorization](1), but is not rate-limited.
.post('/create', create)
.patch('/update/:id', authValidate(roleSet.librarian), update)
.patch('/myupdate', authValidate(roleSet.all), myupdate)
.get('/me', authValidate(roleSet.all), mydata)
Fixed Show fixed Hide fixed
.get('/EasterEgg', getVersion);

// .delete('/delete/:id', authValidate(roleSet.librarian), deleteUser);
18 changes: 18 additions & 0 deletions backend/src/v1/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,25 @@ export const myupdate = async (req: Request, res: Response, next: NextFunction)
return 0;
};

export const mydata = async (
req: Request,
res: Response,
) => {
console.log(req.user);
const { id: tokenId } = req.user as any;
try {
const user = await usersService.searchUserById(parseInt(tokenId, 10));
console.log(user);
if (user.items.length === 0) return res.status(404).send('Not Found');
return res.status(200).json(user.items[0]);
} catch (error: any) {
logger.error(error);
return res.status(500).send('Internal Server Error');
}
};

export const getVersion = async (req: Request, res: Response) => {

res.status(200).send({ version: 'gshim.v1' });
return 0;
};
Expand Down