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
reservation-service
Commits
90beadc9
Commit
90beadc9
authored
Sep 22, 2020
by
CHAERIN KIM
Browse files
logout 새로고침
parent
0ffaebc2
Changes
7
Hide whitespace changes
Inline
Side-by-side
server/client/src/Components/Menu.js
View file @
90beadc9
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
{
Link
}
from
'
react-router-dom
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
styled
from
'
styled-components
'
;
import
styled
from
'
styled-components
'
;
const
Nav
=
styled
.
nav
`
const
Nav
=
styled
.
nav
`
...
@@ -7,13 +7,23 @@ const Nav = styled.nav`
...
@@ -7,13 +7,23 @@ const Nav = styled.nav`
`
`
function
Menu
()
{
function
Menu
()
{
const
[
state
,
setState
]
=
useState
()
if
(
state
)
return
<
Redirect
to
=
"
/
"
/>
;
function
logout
()
{
localStorage
.
removeItem
(
'
token
'
);
alert
(
"
로그아웃 되었습니다.
"
);
setState
(
true
);
}
return
(
return
(
<
Nav
className
=
"
navbar sticky-top navbar-expand-md
"
>
<
Nav
className
=
"
navbar sticky-top navbar-expand-md
"
>
<
Link
to
=
"
/home
"
className
=
"
navbar-brand
"
>
대관
서비스
<
/Link
>
<
Link
to
=
"
/home
"
className
=
"
navbar-brand
"
>
대관
서비스
<
/Link
>
<
button
className
=
"
navbar-toggler
"
type
=
"
button
"
data
-
toggle
=
"
collapse
"
data
-
target
=
"
#collapsibleNavbar
"
aria
-
controls
=
"
collapsibleNavbar
"
>
<
button
className
=
"
navbar-toggler
"
type
=
"
button
"
data
-
toggle
=
"
collapse
"
data
-
target
=
"
#collapsibleNavbar
"
aria
-
controls
=
"
collapsibleNavbar
"
>
<
span
className
=
"
navbar-toggler-icon
"
><
/span
>
<
span
className
=
"
navbar-toggler-icon
"
><
/span
>
<
/button
>
<
/button
>
<
div
className
=
"
collapse navbar-collapse
"
id
=
"
collapsibleNavbar
"
>
<
div
className
=
"
collapse navbar-collapse
justify-content-between
"
id
=
"
collapsibleNavbar
"
>
<
ul
className
=
"
navbar-nav
"
>
<
ul
className
=
"
navbar-nav
"
>
<
li
className
=
"
nav-item
"
>
<
li
className
=
"
nav-item
"
>
<
Link
to
=
"
/home
"
className
=
"
nav-link
"
>
대관
현황
<
/Link
>
<
Link
to
=
"
/home
"
className
=
"
nav-link
"
>
대관
현황
<
/Link
>
...
@@ -27,8 +37,11 @@ function Menu() {
...
@@ -27,8 +37,11 @@ function Menu() {
<
li
className
=
"
nav-item
"
>
<
li
className
=
"
nav-item
"
>
<
Link
to
=
"
/notice
"
className
=
"
nav-link
"
>
공지사항
<
/Link
>
<
Link
to
=
"
/notice
"
className
=
"
nav-link
"
>
공지사항
<
/Link
>
<
/li
>
<
/li
>
<
/ul
>
<
/ul
>
<
div
>
<
button
onClick
=
{
logout
}
type
=
"
button
"
>
로그아웃
<
/button
>
<
button
><
Link
to
=
"
/signup
"
>
회원가입
<
/Link></
button
>
<
/div
>
<
/div
>
<
/div
>
<
/Nav
>
<
/Nav
>
)
)
...
...
server/client/src/Components/PrivateRoute.js
0 → 100644
View file @
90beadc9
import
React
from
'
react
'
;
import
{
Redirect
,
Route
}
from
"
react-router-dom
"
;
export
const
PrivateRoute
=
({
component
:
Component
,
...
rest
})
=>
(
<
Route
{...
rest
}
render
=
{
props
=>
(
localStorage
.
getItem
(
"
token
"
)
!==
null
)
?
(
<
Component
{...
props
}
/
>
)
:
(
<
Redirect
to
=
{{
pathname
:
"
/login
"
,
state
:
{
match
:
props
.
location
}
}}
/
>
)
}
/
>
)
\ No newline at end of file
server/client/src/Pages/HomePage.js
View file @
90beadc9
...
@@ -8,7 +8,7 @@ function Home() {
...
@@ -8,7 +8,7 @@ function Home() {
<
Menu
/>
<
Menu
/>
<
div
className
=
"
container
"
>
<
div
className
=
"
container
"
>
home
home
<
button
><
Link
to
=
"
/
"
>
로그인
<
/Link></
button
>
<
button
><
Link
to
=
"
/
login
"
>
로그인
<
/Link></
button
>
<
button
><
Link
to
=
"
/signup
"
>
회원가입
<
/Link></
button
>
<
button
><
Link
to
=
"
/signup
"
>
회원가입
<
/Link></
button
>
<
/div
>
<
/div
>
<
/div
>
<
/div
>
...
...
server/client/src/Pages/LoginPage.js
View file @
90beadc9
...
@@ -32,7 +32,7 @@ function Login() {
...
@@ -32,7 +32,7 @@ function Login() {
initialValues
=
{{
id
:
''
,
password
:
''
}}
initialValues
=
{{
id
:
''
,
password
:
''
}}
validationSchema
=
{
Yup
.
object
({
validationSchema
=
{
Yup
.
object
({
id
:
Yup
.
string
()
id
:
Yup
.
string
()
.
required
(
'
아이디를
입력해주세요.
'
),
.
required
(
'
학번을
입력해주세요.
'
),
password
:
Yup
.
string
()
password
:
Yup
.
string
()
.
required
(
'
비밀번호를 입력해주세요.
'
)
.
required
(
'
비밀번호를 입력해주세요.
'
)
.
min
(
8
,
'
8자 이상 입력해주세요.
'
),
.
min
(
8
,
'
8자 이상 입력해주세요.
'
),
...
@@ -71,10 +71,10 @@ function Login() {
...
@@ -71,10 +71,10 @@ function Login() {
<
div
className
=
"
form-group mb-4
"
>
<
div
className
=
"
form-group mb-4
"
>
<
input
<
input
className
=
{(
touched
.
id
&&
errors
.
id
?
'
form-control is-invalid
'
:
"
form-control
"
)}
className
=
{(
touched
.
id
&&
errors
.
id
?
'
form-control is-invalid
'
:
"
form-control
"
)}
type
=
"
text
"
type
=
"
number
"
name
=
"
id
"
name
=
"
id
"
{...
getFieldProps
(
'
id
'
)}
{...
getFieldProps
(
'
id
'
)}
placeholder
=
"
Input
i
d
"
placeholder
=
"
Input
Student I
d
"
/>
/>
{
touched
.
id
&&
errors
.
id
?
(
{
touched
.
id
&&
errors
.
id
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
id
}
<
/div
>
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
id
}
<
/div
>
...
@@ -96,6 +96,7 @@ function Login() {
...
@@ -96,6 +96,7 @@ function Login() {
Login
Login
<
/button
>
<
/button
>
<
button
><
Link
to
=
"
/home
"
>
홈
<
/Link></
button
>
<
button
><
Link
to
=
"
/home
"
>
홈
<
/Link></
button
>
<
div
><
/div
>
<
Link
to
=
"
/signup
"
>
비밀번호를
잊으셨나요
?
<
/Link
>
<
Link
to
=
"
/signup
"
>
비밀번호를
잊으셨나요
?
<
/Link
>
<
div
><
/div
>
<
div
><
/div
>
<
Link
to
=
"
/signup
"
>
회원이
아니신가요
?
<
/Link
>
<
Link
to
=
"
/signup
"
>
회원이
아니신가요
?
<
/Link
>
...
...
server/client/src/Pages/SignupPage.js
View file @
90beadc9
...
@@ -20,7 +20,7 @@ function Signup() {
...
@@ -20,7 +20,7 @@ function Signup() {
name
:
Yup
.
string
()
name
:
Yup
.
string
()
.
required
(
'
이름을 입력해주세요.
'
),
.
required
(
'
이름을 입력해주세요.
'
),
id
:
Yup
.
string
()
id
:
Yup
.
string
()
.
required
(
'
아이디를
입력해주세요.
'
),
.
required
(
'
학번을
입력해주세요.
'
),
password
:
Yup
.
string
()
password
:
Yup
.
string
()
.
required
(
'
비밀번호를 입력해주세요.
'
)
.
required
(
'
비밀번호를 입력해주세요.
'
)
.
min
(
8
,
'
8자 이상 입력해주세요.
'
),
.
min
(
8
,
'
8자 이상 입력해주세요.
'
),
...
@@ -72,10 +72,10 @@ function Signup() {
...
@@ -72,10 +72,10 @@ function Signup() {
<
div
className
=
"
form-group mb-4
"
>
<
div
className
=
"
form-group mb-4
"
>
<
input
<
input
className
=
{(
touched
.
id
&&
errors
.
id
?
'
form-control is-invalid
'
:
"
form-control
"
)}
className
=
{(
touched
.
id
&&
errors
.
id
?
'
form-control is-invalid
'
:
"
form-control
"
)}
type
=
"
text
"
type
=
"
number
"
name
=
"
id
"
name
=
"
id
"
{...
getFieldProps
(
'
id
'
)}
{...
getFieldProps
(
'
id
'
)}
placeholder
=
"
Input
i
d
"
placeholder
=
"
Input
Student I
d
"
/>
/>
{
touched
.
id
&&
errors
.
id
?
(
{
touched
.
id
&&
errors
.
id
?
(
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
id
}
<
/div
>
<
div
className
=
"
invalid-feedback text-left
"
>
{
errors
.
id
}
<
/div
>
...
@@ -108,8 +108,8 @@ function Signup() {
...
@@ -108,8 +108,8 @@ function Signup() {
<
button
type
=
"
submit
"
className
=
"
btn btn-dark
"
disabled
=
{
isSubmitting
}
>
<
button
type
=
"
submit
"
className
=
"
btn btn-dark
"
disabled
=
{
isSubmitting
}
>
Sign
Up
Sign
Up
<
/button
>
<
/button
>
<
button
><
Link
to
=
"
/
"
>
로그인
<
/Link></
button
>
<
button
><
Link
to
=
"
/
login
"
>
로그인
<
/Link></
button
>
<
button
><
Link
to
=
"
/
home
"
>
홈
<
/Link></
button
>
<
button
><
Link
to
=
"
/
"
>
홈
<
/Link></
button
>
<
/form
>
<
/form
>
<
/div
>
<
/div
>
)}
)}
...
...
server/client/src/index.js
View file @
90beadc9
...
@@ -4,7 +4,7 @@ import * as serviceWorker from './serviceWorker';
...
@@ -4,7 +4,7 @@ import * as serviceWorker from './serviceWorker';
import
{
BrowserRouter
as
Router
,
Route
,
Redirect
,
Switch
}
from
'
react-router-dom
'
;
import
{
BrowserRouter
as
Router
,
Route
,
Redirect
,
Switch
}
from
'
react-router-dom
'
;
import
'
bootstrap/dist/css/bootstrap.css
'
;
import
'
bootstrap/dist/css/bootstrap.css
'
;
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
//
import { PrivateRoute } from './PrivateRoute';
import
{
PrivateRoute
}
from
'
./
Components/
PrivateRoute
'
;
import
Login
from
'
./Pages/LoginPage
'
;
import
Login
from
'
./Pages/LoginPage
'
;
import
Home
from
'
./Pages/HomePage
'
;
import
Home
from
'
./Pages/HomePage
'
;
...
@@ -20,7 +20,8 @@ axios.defaults.validateStatus = function (status) {
...
@@ -20,7 +20,8 @@ axios.defaults.validateStatus = function (status) {
ReactDOM
.
render
(
ReactDOM
.
render
(
<
Router
>
<
Router
>
<
Switch
>
<
Switch
>
<
Route
exact
path
=
"
/
"
component
=
{
Login
}
/
>
<
PrivateRoute
exact
path
=
"
/
"
component
=
{
Home
}
/
>
<
Route
path
=
"
/login
"
component
=
{
Login
}
/
>
<
Route
path
=
"
/home
"
component
=
{
Home
}
/
>
<
Route
path
=
"
/home
"
component
=
{
Home
}
/
>
<
Route
path
=
"
/signup
"
component
=
{
Signup
}
/
>
<
Route
path
=
"
/signup
"
component
=
{
Signup
}
/
>
<
Route
path
=
"
/apply
"
component
=
{
Apply
}
/
>
<
Route
path
=
"
/apply
"
component
=
{
Apply
}
/
>
...
...
server/routes/login.js
View file @
90beadc9
...
@@ -36,7 +36,7 @@ router.post('/', function (req, res, next) {
...
@@ -36,7 +36,7 @@ router.post('/', function (req, res, next) {
const
token
=
jwt
.
sign
({
const
token
=
jwt
.
sign
({
id
:
users
.
id
,
id
:
users
.
id
,
},
process
.
env
.
JWT_SECRET
,
{
},
process
.
env
.
JWT_SECRET
,
{
expiresIn
:
'
1
0
m
'
,
// 12시간
expiresIn
:
'
1m
'
,
});
});
return
res
.
status
(
201
).
json
({
return
res
.
status
(
201
).
json
({
token
,
token
,
...
...
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