定数を使ってレスポンスするように

This commit is contained in:
ろむねこ 2024-07-04 10:31:30 +09:00
parent 4aa4997a2d
commit 12ba1bf265
Signed by: Fujimatsu
GPG Key ID: FA1F39A1BA37D168

View File

@ -1,18 +1,15 @@
import { Request, Response, NextFunction } from "express";
import { Role } from "@src/enums";
import { jwtVerifyErrorResponse, notPermittedResponse } from "@src/models/commons/responses";
export default function verifyParent(req: Request, res: Response, next: NextFunction) {
if (req.user) {
if (req.user.claims.role === Role.PARENT) {
next();
} else {
res.status(401).json({
message: '権限がありません(保護者のみ利用可能なAPIです)'
});
res.status(notPermittedResponse().statusCode).json(notPermittedResponse().body);
}
} else {
res.status(500).json({
message: 'エラーが発生しました(JWT解析結果が不正/未設定です)'
});
res.status(jwtVerifyErrorResponse().statusCode).json(jwtVerifyErrorResponse().body);
}
}