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
shopping-mall
Commits
d3301a50
Commit
d3301a50
authored
Jan 11, 2021
by
이재연
Browse files
로그아웃 버튼 수정중
parent
42ab4e72
Changes
7
Hide whitespace changes
Inline
Side-by-side
client/src/Components/MainNav.js
View file @
d3301a50
import
React
,
{
useState
,
useEffect
,
useRef
}
from
'
react
'
;
import
{
Navbar
,
Nav
}
from
'
react-bootstrap
'
;
import
{
Navbar
,
Nav
,
Row
}
from
'
react-bootstrap
'
;
import
logo
from
'
../footprint.svg
'
;
import
cart
from
'
../cart.svg
'
;
import
option
from
'
../option.svg
'
;
import
{
handleLogout
,
isAuthenticated
}
from
'
../utils/auth
'
function
MainNav
()
{
function
handleClick
()
{
alert
(
'
로그아웃이 완료되었습니다.
'
)
window
.
location
.
href
=
"
/home
"
}
const
user
=
isAuthenticated
()
return
(
<
Navbar
sticky
=
"
top
"
style
=
{{
background
:
"
#CDC5C2
"
}}
>
...
...
@@ -16,13 +14,17 @@ function MainNav() {
<
img
src
=
{
logo
}
width
=
"
24
"
height
=
"
24
"
/>
{
'
'
}
KU
#
<
/Navbar.Brand
>
<
Nav
className
=
"
justify-content-end
"
>
<
Nav
.
Link
className
=
"
text-light
"
href
=
"
/login
"
>
Login
<
/Nav.Link
>
<
Nav
.
Link
className
=
"
text-light
"
href
=
"
/signup
"
>
Signup
<
/Nav.Link
>
<
Nav
>
{
user
?
<
Nav
.
Link
className
=
"
text-light
"
onClick
=
{()
=>
handleLogout
()}
>
Logout
<
/Nav.Link
>
:
(
<>
<
Nav
.
Link
className
=
"
text-light
"
href
=
'
/login
'
>
Login
<
/Nav.Link
>
<
Nav
.
Link
className
=
"
text-light
"
href
=
'
/signup
'
>
Sign
Up
<
/Nav.Link
>
<
/
>
)}
<
Nav
.
Link
href
=
"
/shoppingcart
"
>
<
img
src
=
{
cart
}
width
=
"
30
"
height
=
"
30
"
/>
<
/Nav.Link
>
<
Nav
.
Link
className
=
"
text-light
"
onClick
=
{()
=>
handleClick
()}
>
Logout
<
/Nav.Link
>
<
Nav
.
Link
href
=
"
/admin
"
>
<
img
src
=
{
option
}
width
=
"
30
"
height
=
"
30
"
/>
<
/Nav.Link
>
...
...
client/src/Pages/Login.js
View file @
d3301a50
...
...
@@ -20,6 +20,11 @@ function Login() {
const
[
error
,
setError
]
=
useState
(
''
)
const
[
success
,
setSuccess
]
=
useState
(
false
)
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
setUser
({
...
user
,
[
name
]:
value
})
}
async
function
handleSubmit
(
event
)
{
event
.
preventDefault
()
const
form
=
event
.
currentTarget
;
...
...
@@ -34,81 +39,75 @@ function Login() {
handleLogin
()
setSuccess
(
true
)
}
catch
(
error
)
{
catchErrors
(
error
,
setError
)
console
.
log
(
error
)
}
}
if
(
success
)
{
return
<
Redirect
to
=
'
/
'
/>
}
}
function
handleChange
(
event
)
{
const
{
name
,
value
}
=
event
.
target
setUser
({
...
user
,
[
name
]:
value
})
if
(
success
)
{
alert
(
'
로그인 되었습니다.
'
)
return
<
Redirect
to
=
'
/
'
/>
}
}
return
(
<
div
>
return
(
<
div
>
<
Nav1
/>
<
Nav2
/>
<
Container
className
=
"
my-5
"
>
<
Row
className
=
"
justify-content-center
"
>
<
Col
md
=
{
5
}
xs
=
{
10
}
className
=
"
border
"
style
=
{{
background
:
'
#F7F3F3
'
}}
>
<
h3
className
=
"
text-center mt-5
"
>
Login
<
/h3
>
{
error
&&
<
Alert
variant
=
'
danger
'
>
{
error
}
<
/Alert>
}
<
Form
noValidate
validated
=
{
validated
}
onSubmit
=
{
handleSubmit
}
className
=
"
p-5
"
>
<
Form
.
Group
controlId
=
"
formBasicId
"
>
<
Form
.
Row
>
<
Col
sm
=
{
4
}
xs
=
{
6
}
as
=
{
Form
.
Label
}
for
=
"
id
"
>
아이디
<
/Col
>
<
Col
sm
=
{
8
}
xs
=
{
12
}
as
=
{
Form
.
Control
}
required
type
=
"
text
"
name
=
"
id
"
placeholder
=
"
ID
"
value
=
{
user
.
id
}
onChange
=
{
handleChange
}
style
=
{{
width
:
'
160px
'
}}
>
<
/Col
>
<
Form
.
Control
.
Feedback
className
=
"
text-center
"
type
=
"
invalid
"
>
아이디를
입력하세요
.
<
/Form.Control.Feedback
>
<
/Form.Row
>
<
/Form.Group
>
<
Container
className
=
"
my-5
"
>
<
Row
className
=
"
justify-content-center
"
>
<
Col
md
=
{
5
}
xs
=
{
10
}
className
=
"
border
"
style
=
{{
background
:
'
#F7F3F3
'
}}
>
<
h3
className
=
"
text-center mt-5
"
>
Login
<
/h3
>
{
error
&&
<
Alert
variant
=
'
danger
'
>
{
error
}
<
/Alert>
}
<
Form
noValidate
validated
=
{
validated
}
onSubmit
=
{
handleSubmit
}
className
=
"
p-5
"
>
<
Form
.
Group
controlId
=
"
formBasicId
"
>
<
Form
.
Row
>
<
Col
sm
=
{
4
}
xs
=
{
6
}
as
=
{
Form
.
Label
}
for
=
"
id
"
>
아이디
<
/Col
>
<
Col
sm
=
{
8
}
xs
=
{
12
}
as
=
{
Form
.
Control
}
required
type
=
"
text
"
name
=
"
id
"
placeholder
=
"
ID
"
value
=
{
user
.
id
}
onChange
=
{
handleChange
}
style
=
{{
width
:
'
160px
'
}}
>
<
/Col
>
<
Form
.
Control
.
Feedback
className
=
"
text-center
"
type
=
"
invalid
"
>
아이디를
입력하세요
.
<
/Form.Control.Feedback
>
<
/Form.Row
>
<
/Form.Group
>
<
Form
.
Group
controlId
=
"
formBasicPassword
"
>
<
Form
.
Row
>
<
Col
sm
=
{
4
}
xs
=
{
6
}
as
=
{
Form
.
Label
}
for
=
"
password
"
>
비밀번호
<
/Col
>
<
Col
sm
=
{
8
}
xs
=
{
12
}
as
=
{
Form
.
Control
}
type
=
"
password
"
name
=
"
password
"
value
=
{
user
.
password
}
placeholder
=
"
Password
"
onChange
=
{
handleChange
}
style
=
{{
width
:
'
160px
'
}}
required
/>
<
Form
.
Control
.
Feedback
className
=
"
text-center
"
type
=
"
invalid
"
>
비밀번호를
입력하세요
.
<
Form
.
Group
controlId
=
"
formBasicPassword
"
>
<
Form
.
Row
>
<
Col
sm
=
{
4
}
xs
=
{
6
}
as
=
{
Form
.
Label
}
for
=
"
password
"
>
비밀번호
<
/Col
>
<
Col
sm
=
{
8
}
xs
=
{
12
}
as
=
{
Form
.
Control
}
type
=
"
password
"
name
=
"
password
"
value
=
{
user
.
password
}
placeholder
=
"
Password
"
onChange
=
{
handleChange
}
style
=
{{
width
:
'
160px
'
}}
required
/>
<
Form
.
Control
.
Feedback
className
=
"
text-center
"
type
=
"
invalid
"
>
비밀번호를
입력하세요
.
<
/Form.Control.Feedback
>
<
/Form.Row
>
<
/Form.Group
>
<
Button
style
=
{{
background
:
'
#91877F
'
,
borderColor
:
'
#91877F
'
}}
type
=
"
submit
"
block
>
Login
<
/Button
>
<
div
className
=
"
loginLine
"
>
<
Link
to
=
"
/signup
"
style
=
{{
color
:
'
#91877F
'
}}
>
회원이
아니십니까
?
<
/Link
>
<
/div
>
<
/Form
>
<
/Col
>
<
/Row
>
<
/Container
>
<
/div
>
)
<
/Form.Row
>
<
/Form.Group
>
<
Button
style
=
{{
background
:
'
#91877F
'
,
borderColor
:
'
#91877F
'
}}
type
=
"
submit
"
block
>
Login
<
/Button
>
<
div
className
=
"
loginLine
"
>
<
Link
to
=
"
/signup
"
style
=
{{
color
:
'
#91877F
'
}}
>
회원이
아니십니까
?
<
/Link
>
<
/div
>
<
/Form
>
<
/Col
>
<
/Row
>
<
/Container
>
<
/div
>
)
}
export
default
Login
\ No newline at end of file
client/src/Pages/Logout.js
deleted
100644 → 0
View file @
42ab4e72
// import { Button } from 'bootstrap'
// import React from 'react'
// import { handleLogout } from '../utils/auth'
// function logout() {
// return (
// <div>
// <Button onClick={()=>handleLogout()}>Logout</Button>
// </div>
// )
// }
// export default logout
client/src/Pages/ProductsList.js
View file @
d3301a50
...
...
@@ -30,17 +30,18 @@ function ProductsList() {
<
MainNav
/>
<
SubNav
/>
<
Container
>
<
Row
className
=
"
justify-content-center mx-0 my-4
"
>
<
Col
sm
=
{
10
}
>
<
h1
style
=
{{
fontSize
:
"
3rem
"
}}
>
OUTER
<
/h1
>
<
Row
>
<
Col
sm
=
{
10
}
xs
=
{
12
}
>
<
h1
style
=
{{
fontSize
:
"
3rem
"
}}
className
=
"
text-center
"
>
OUTER
<
/h1
>
<
div
>
{
sub
.
map
((
ele
)
=>
(
<
Button
className
=
"
m-1
"
>
{
ele
}
<
/Button
>
<
Button
className
=
"
justify-content-center
m-1
"
>
{
ele
}
<
/Button
>
))}
<
/div
>
<
/Col
>
<
/Row
>
<
Row
className
=
"
justify-content-between mx-0 my-5
"
>
<
Dropdown
>
<
Dropdown
.
Toggle
>
정렬
<
/Dropdown.Toggle
>
<
Form
as
=
{
Row
}
onSubmit
=
{
handleSubmit
}
className
=
"
justify-content-end mx-0
"
>
<
Dropdown
>
<
Dropdown
.
Toggle
className
=
"
mx-2
"
>
정렬
<
/Dropdown.Toggle
>
<
Dropdown
.
Menu
>
<
Dropdown
.
Item
>
인기상품
<
/Dropdown.Item
>
<
Dropdown
.
Item
>
신상품
<
/Dropdown.Item
>
...
...
@@ -48,15 +49,13 @@ function ProductsList() {
<
Dropdown
.
Item
>
높은가격
<
/Dropdown.Item
>
<
/Dropdown.Menu
>
<
/Dropdown
>
<
Form
as
=
{
Row
}
onSubmit
=
{
handleSubmit
}
className
=
"
justify-content-end mx-0
"
>
<
FormControl
type
=
"
text
"
placeholder
=
"
Search
"
style
=
{{
width
:
"
13rem
"
}}
/
>
<
Button
type
=
"
submit
"
className
=
"
search px-2
"
>
<
FormControl
type
=
"
text
"
placeholder
=
"
Search
"
style
=
{{
width
:
"
13rem
"
}}
/
>
<
Button
type
=
"
submit
"
className
=
"
search px-2 mb-1
"
>
<
img
src
=
{
search
}
width
=
"
20
"
height
=
"
20
"
/>
<
/Button
>
<
Button
sm
=
{
2
}
xs
=
{
6
}
type
=
"
button
"
href
=
"
/regist
"
className
=
"
ml-1
"
>
상품
등록
<
/Button
>
<
/Form
>
<
/Row
>
<
Row
className
=
"
justify-content-start m-
5
"
>
<
Row
md
=
{
8
}
sm
=
{
12
}
className
=
"
justify-content-start m-
2
"
>
<
Card
className
=
"
mt-5
"
style
=
{{
width
:
"
18rem
"
,
margin
:
"
auto
"
}}
>
<
Card
.
Img
variant
=
"
top
"
src
=
"
https://img.sonyunara.com/files/goods/67460/1607053816_0.jpg
"
style
=
{{
objectFit
:
"
contain
"
,
height
:
"
22rem
"
}}
/
>
<
Card
.
Body
>
...
...
client/src/utils/auth.js
View file @
d3301a50
...
...
@@ -7,4 +7,14 @@ export function handleLogin(){
export
async
function
handleLogout
(){
localStorage
.
removeItem
(
'
loginStatus
'
)
await
axios
.
get
(
'
/api/auth/logout
'
)
window
.
location
.
href
=
'
/
'
}
export
function
isAuthenticated
(){
const
userId
=
localStorage
.
getItem
(
'
loginStatus
'
)
if
(
userId
){
return
userId
}
else
{
return
false
}
}
\ No newline at end of file
server/controllers/auth.controller.js
View file @
d3301a50
...
...
@@ -33,9 +33,9 @@ const login = async(req,res)=>{
}
}
//
const logout =(req,res)=>{
//
res.clearCookie('token')
//
res.send('로그아웃 되었습니다.')
//
}
const
logout
=
(
req
,
res
)
=>
{
res
.
clearCookie
(
'
token
'
)
res
.
send
(
'
로그아웃 되었습니다.
'
)
}
export
default
{
login
}
\ No newline at end of file
export
default
{
login
,
logout
}
\ No newline at end of file
server/routes/auth.routes.js
View file @
d3301a50
...
...
@@ -6,7 +6,7 @@ const router = express.Router()
router
.
route
(
'
/login
'
)
.
post
(
authCtrl
.
login
)
//
router.route('/logout')
//
.get(authCtrl.logout)
router
.
route
(
'
/logout
'
)
.
get
(
authCtrl
.
logout
)
export
default
router
\ No newline at end of file
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