-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
42 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
// 로그인된 상태에만 접근할 수 있는 라우터(rooms)를 위한 미들웨어입니다. | ||
import { type Request, type Response, type NextFunction } from "express"; | ||
import type { RequestHandler } from "express"; | ||
import { isLogin, getLoginInfo } from "@/modules/auths/login"; | ||
|
||
const authMiddleware = (req: Request, res: Response, next: NextFunction) => { | ||
if (!isLogin(req)) { | ||
res.status(403).json({ | ||
const authMiddleware: RequestHandler = (req, res, next) => { | ||
if (!isLogin(req)) | ||
return res.status(403).json({ | ||
error: "not logged in", | ||
}); | ||
} else { | ||
const { id, oid } = getLoginInfo(req); | ||
req.userId = id; | ||
req.userOid = oid; | ||
next(); | ||
} | ||
|
||
const { id, oid } = getLoginInfo(req); | ||
req.userId = id; | ||
req.userOid = oid; | ||
next(); | ||
}; | ||
|
||
export default authMiddleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import rateLimit from "express-rate-limit"; | ||
|
||
const limiter = rateLimit({ | ||
const limitRateMiddleware = rateLimit({ | ||
windowMs: 15 * 60 * 1000, // 15 minutes | ||
max: 1500, // Limit each IP to 1500 requests per `window` (here, per 15 minutes) | ||
standardHeaders: true, // Return rate limit info in the `RateLimit-*` headers | ||
legacyHeaders: false, // Disable the `X-RateLimit-*` headers | ||
}); | ||
|
||
export default limiter; | ||
export default limitRateMiddleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
import { type Request, type Response, type NextFunction } from "express"; | ||
import type { RequestHandler } from "express"; | ||
|
||
const originValidatorMiddleware = ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
const originValidatorMiddleware: RequestHandler = (req, res, next) => { | ||
req.origin = | ||
req.headers.origin || | ||
req.headers.referer || | ||
req.session?.loginAfterState?.redirectOrigin; // sparcssso/callback 요청은 헤더에 origin이 없음 | ||
|
||
if (!req.origin) { | ||
if (!req.origin) | ||
return res.status(400).json({ | ||
error: "Bad Request : request must have origin in header", | ||
}); | ||
} | ||
return next(); | ||
|
||
next(); | ||
}; | ||
|
||
export default originValidatorMiddleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
import { type Request, type Response, type NextFunction } from "express"; | ||
import type { RequestHandler } from "express"; | ||
import { validationResult } from "express-validator"; | ||
|
||
const validatorMiddleware = ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
const validatorMiddleware: RequestHandler = (req, res, next) => { | ||
const validationErrors = validationResult(req); | ||
if (!validationErrors.isEmpty()) { | ||
if (!validationErrors.isEmpty()) | ||
return res.status(400).json({ | ||
error: "validation : bad request", | ||
}); | ||
} | ||
return next(); | ||
|
||
next(); | ||
}; | ||
|
||
export default validatorMiddleware; |