Commit 35f8698d authored by Lee Soobeom's avatar Lee Soobeom
Browse files

useNavigate useLocation

parent 0a4db016
......@@ -51,11 +51,15 @@ export default function Posting() {
formdata.append("picture", filelist?.[0]);
const res = await postApi.createFileAndPost(formdata);
return res;
} else {
for (var i = 0; i < filelist.length; i++) {
formdata.append("picture", filelist?.[i]);
}
const res = await postApi.createFileAndPost(formdata);
return res;
}
}
};
......@@ -69,10 +73,10 @@ export default function Posting() {
if (postingFormMatch(user, file)) {
setLoading(true);
if (file) {
const res = sendImg2Db(file);
// console.log(res);
const postRes = await sendImg2Db(file);
// console.log("Newpost Info", postRes);
navigate("/board", { replace: true, state: postRes });
}
navigate("/board", { replace: true });
setSuccess(true);
setError("");
}
......
......@@ -6,11 +6,37 @@ import isEmail from "validator/lib/isEmail";
import { asyncWrap } from "../helpers";
import { roleDb, userDb } from "../db";
import { jwtCofig, envConfig, cookieConfig } from "../config";
import { TypedRequest } from "../types";
export interface TypedRequestAuth<T> extends Request {
auth: T;
}
/**
* 함수를 호출하기 전에 req에 user 정보를 지정해야 합니다.
*/
export const authenticate = asyncWrap(
async (reqExp: Request, res: Response, next: NextFunction) => {
try {
const req = reqExp as TypedRequest;
if (req.auth) {
const { userId } = req.auth;
const user = req.user;
if (user && user.id === userId) {
return next();
} else {
throw new Error("권한이 필요합니다");
}
} else {
throw new Error("로그인이 필요합니다");
}
} catch (error: any) {
console.log(error);
return res.status(401).send(error.message || "권한 없음");
}
}
);
/**
* 지정된 역할 이상으로 권한이 있는지를 판단하는 미들웨어를 반환합니다.
* @param roleName 역할 문자열
......
......@@ -11,7 +11,7 @@ router.route("/files/:postId").get(authCtrl.requireLogin, postCtrl.getFiles);
router
.route("/:postId")
.post(authCtrl.requireLogin, postCtrl.addCounts)
.delete(authCtrl.requireLogin, postCtrl.deleteOnePost) // +authenticate
.delete(authCtrl.requireLogin, authCtrl.authenticate, postCtrl.deleteOnePost)
.put(authCtrl.requireLogin, postCtrl.updateOnePost);
router.param("postId", postCtrl.userByPostId);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment