Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
travel
Commits
35f8698d
Commit
35f8698d
authored
Jul 27, 2022
by
Lee Soobeom
Browse files
useNavigate useLocation
parent
0a4db016
Changes
3
Hide whitespace changes
Inline
Side-by-side
frontend/src/post/posting.tsx
View file @
35f8698d
...
...
@@ -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
(
""
);
}
...
...
src/controllers/auth.controller.ts
View file @
35f8698d
...
...
@@ -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 역할 문자열
...
...
src/routes/post.route.ts
View file @
35f8698d
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment