Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박민정
/
We-Shop
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박민정
2021-06-05 23:53:22 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8f8abaadcee7faf797680c0019e29d0d345c64bb
8f8abaad
1 parent
42bc1afc
[feat] Create page access authority with login state
Show whitespace changes
Inline
Side-by-side
Showing
35 changed files
with
92 additions
and
24 deletions
boiler-plate/.gitignore → We-Shop/.gitignore
boiler-plate/client/.gitignore → We-Shop/client/.gitignore
boiler-plate/client/README.md → We-Shop/client/README.md
boiler-plate/client/package-lock.json → We-Shop/client/package-lock.json
boiler-plate/client/package.json → We-Shop/client/package.json
boiler-plate/client/public/favicon.ico → We-Shop/client/public/favicon.ico
boiler-plate/client/public/index.html → We-Shop/client/public/index.html
boiler-plate/client/public/logo192.png → We-Shop/client/public/logo192.png
boiler-plate/client/public/logo512.png → We-Shop/client/public/logo512.png
boiler-plate/client/public/manifest.json → We-Shop/client/public/manifest.json
boiler-plate/client/public/robots.txt → We-Shop/client/public/robots.txt
boiler-plate/client/src/App.css → We-Shop/client/src/App.css
boiler-plate/client/src/App.js → We-Shop/client/src/App.js
boiler-plate/client/src/_actions/types.js → We-Shop/client/src/_actions/types.js
boiler-plate/client/src/_actions/user_action.js → We-Shop/client/src/_actions/user_action.js
boiler-plate/client/src/_reducers/index.js → We-Shop/client/src/_reducers/index.js
boiler-plate/client/src/_reducers/user_reducer.js → We-Shop/client/src/_reducers/user_reducer.js
boiler-plate/client/src/components/views/Footer/Footer.js → We-Shop/client/src/components/views/Footer/Footer.js
boiler-plate/client/src/components/views/LandingPage/LandingPage.js → We-Shop/client/src/components/views/LandingPage/LandingPage.js
boiler-plate/client/src/components/views/LoginPage/LoginPage.js → We-Shop/client/src/components/views/LoginPage/LoginPage.js
boiler-plate/client/src/components/views/NavBar/NavBar.js → We-Shop/client/src/components/views/NavBar/NavBar.js
boiler-plate/client/src/components/views/RegisterPage/RegisterPage.js → We-Shop/client/src/components/views/RegisterPage/RegisterPage.js
We-Shop/client/src/hoc/authentication.js
boiler-plate/client/src/index.css → We-Shop/client/src/index.css
boiler-plate/client/src/index.js → We-Shop/client/src/index.js
boiler-plate/client/src/reportWebVitals.js → We-Shop/client/src/reportWebVitals.js
boiler-plate/client/src/setupProxy.js → We-Shop/client/src/setupProxy.js
boiler-plate/client/src/setupTests.js → We-Shop/client/src/setupTests.js
boiler-plate/package-lock.json → We-Shop/package-lock.json
boiler-plate/package.json → We-Shop/package.json
boiler-plate/server/config/key.js → We-Shop/server/config/key.js
boiler-plate/server/config/prod.js → We-Shop/server/config/prod.js
boiler-plate/server/index.js → We-Shop/server/index.js
boiler-plate/server/middleware/auth.js → We-Shop/server/middleware/auth.js
boiler-plate/server/models/User.js → We-Shop/server/models/User.js
boiler-plate
/.gitignore
→
We-Shop
/.gitignore
View file @
8f8abaa
File moved
boiler-plate
/client/.gitignore
→
We-Shop
/client/.gitignore
View file @
8f8abaa
File moved
boiler-plate
/client/README.md
→
We-Shop
/client/README.md
View file @
8f8abaa
File moved
boiler-plate
/client/package-lock.json
→
We-Shop
/client/package-lock.json
View file @
8f8abaa
File moved
boiler-plate
/client/package.json
→
We-Shop
/client/package.json
View file @
8f8abaa
File moved
boiler-plate
/client/public/favicon.ico
→
We-Shop
/client/public/favicon.ico
View file @
8f8abaa
No preview for this file type
boiler-plate
/client/public/index.html
→
We-Shop
/client/public/index.html
View file @
8f8abaa
File moved
boiler-plate
/client/public/logo192.png
→
We-Shop
/client/public/logo192.png
View file @
8f8abaa
5.22 KB
boiler-plate
/client/public/logo512.png
→
We-Shop
/client/public/logo512.png
View file @
8f8abaa
9.44 KB
boiler-plate
/client/public/manifest.json
→
We-Shop
/client/public/manifest.json
View file @
8f8abaa
File moved
boiler-plate
/client/public/robots.txt
→
We-Shop
/client/public/robots.txt
View file @
8f8abaa
File moved
boiler-plate
/client/src/App.css
→
We-Shop
/client/src/App.css
View file @
8f8abaa
File moved
boiler-plate
/client/src/App.js
→
We-Shop
/client/src/App.js
View file @
8f8abaa
import
React
from
"react"
;
import
{
BrowserRouter
as
Router
,
Switch
,
Route
,
Link
//
Link
}
from
"react-router-dom"
;
import
LandingPage
from
'./components/views/LandingPage/LandingPage'
import
LoginPage
from
'./components/views/LoginPage/LoginPage'
import
RegisterPage
from
'./components/views/RegisterPage/RegisterPage'
import
auth
from
'./hoc/authentication'
function
App
()
{
return
(
<
Router
>
<
div
>
{
/*
A <Switch> looks through all its children <Route>
elements and renders the first one whose path
matches the current URL. Use a <Switch> any time
you have multiple routes, but you want only one
of them to render at a time
*/
}
<
Switch
>
<
Route
exact
path
=
"/"
>
<
LandingPage
/>
<
/Route> {/
*
<
Route
exact
path
=
"/"
component
=
{
LandingPage
}
/> 로 해도 똑같은 결과가 나옴!
*
/
}
{
/* null, false에 대한 옵션 설명은 auth로 가서 확인*/
}
<
Route
exact
path
=
"/"
component
=
{
auth
(
LandingPage
,
null
)}
/>
<
Route
path
=
"/login"
>
<
LoginPage
/>
<
/Route
>
<
Route
exact
path
=
"/login"
component
=
{
auth
(
LoginPage
,
false
)}
/
>
<
Route
path
=
"/register"
>
<
RegisterPage
/>
<
/Route
>
<
Route
exact
path
=
"/register"
component
=
{
auth
(
RegisterPage
,
false
)}
/
>
{
/*
<Route exact path="/" component={LandingPage} />
<Route exact path="/login" component={LoginPage}/>
<Route exact path="/register" component={RegisterPage}/>
*/
}
<
/Switch
>
<
/div
>
<
/Router
>
...
...
boiler-plate
/client/src/_actions/types.js
→
We-Shop
/client/src/_actions/types.js
View file @
8f8abaa
...
...
@@ -2,3 +2,4 @@
export
const
LOGIN_USER
=
"login_user"
;
export
const
REGISTER_USER
=
"resgier_user"
;
export
const
AUTH_USER
=
"auth_user"
;
\ No newline at end of file
...
...
boiler-plate
/client/src/_actions/user_action.js
→
We-Shop
/client/src/_actions/user_action.js
View file @
8f8abaa
import
axios
from
'axios'
;
import
{
LOGIN_USER
,
REGISTER_USER
REGISTER_USER
,
AUTH_USER
}
from
'./types'
;
export
function
loginUser
(
logInfo
)
{
const
request
=
axios
.
post
(
'/api/users/login'
,
logInfo
)
// logInfo를 post로 전달
...
...
@@ -21,7 +22,7 @@ export function RegisterUser(regInfo) {
const
request
=
axios
.
post
(
'/api/users/register'
,
regInfo
)
// logInfo를 post로 전달
.
then
(
response
=>
response
.
data
);
// 서버에서 받은 데이터를 request에 저장
return
{
// return을 통해 Reducer로 보냄
return
{
// return을 통해 Reducer로 보냄
.
// Reducer에서 previousState, action을 이용해 nextState로 만들기 때문 :: (previousState, action) => nextState
// request를 reducer로 보내는 작업
...
...
@@ -30,3 +31,14 @@ export function RegisterUser(regInfo) {
payload
:
request
// payroad == response
}
}
export
function
auth
()
{
const
request
=
axios
.
get
(
'/api/users/auth'
)
// logInfo를 post로 전달
.
then
(
response
=>
response
.
data
);
// 서버에서 받은 데이터를 request에 저장
return
{
type
:
"AUTH_USER"
,
payload
:
request
// payroad == response
}
}
\ No newline at end of file
...
...
boiler-plate
/client/src/_reducers/index.js
→
We-Shop
/client/src/_reducers/index.js
View file @
8f8abaa
File moved
boiler-plate
/client/src/_reducers/user_reducer.js
→
We-Shop
/client/src/_reducers/user_reducer.js
View file @
8f8abaa
import
{
LOGIN_USER
,
REGISTER_USER
REGISTER_USER
,
AUTH_USER
}
from
'../_actions/types'
;
...
...
@@ -10,9 +11,15 @@ export default function (prevState = {}, action) {
case
LOGIN_USER
:
return
{...
prevState
,
loginSuccess
:
action
.
payload
}
// 위의 prevState를 그대로 가져오고,
// user_action.js에 있는 payload를 그대로 가져와서 return.
// loginSuccess는 server/index.js 에서 login에 성공하면 json type으로 loginSuccess: true를 전달하라고 했기 때문
break
;
case
REGISTER_USER
:
return
{...
prevState
,
success
:
action
.
payload
}
// success는 server/index.js 에서 register에 성공하면 json type으로 success: true를 전달하라고 했기 때문
break
;
case
AUTH_USER
:
return
{...
prevState
,
user
:
action
.
payload
}
break
;
default
:
return
prevState
;
...
...
boiler-plate
/client/src/components/views/Footer/Footer.js
→
We-Shop
/client/src/components/views/Footer/Footer.js
View file @
8f8abaa
File moved
boiler-plate
/client/src/components/views/LandingPage/LandingPage.js
→
We-Shop
/client/src/components/views/LandingPage/LandingPage.js
View file @
8f8abaa
File moved
boiler-plate
/client/src/components/views/LoginPage/LoginPage.js
→
We-Shop
/client/src/components/views/LoginPage/LoginPage.js
View file @
8f8abaa
File moved
boiler-plate
/client/src/components/views/NavBar/NavBar.js
→
We-Shop
/client/src/components/views/NavBar/NavBar.js
View file @
8f8abaa
File moved
boiler-plate
/client/src/components/views/RegisterPage/RegisterPage.js
→
We-Shop
/client/src/components/views/RegisterPage/RegisterPage.js
View file @
8f8abaa
File moved
We-Shop/client/src/hoc/authentication.js
0 → 100644
View file @
8f8abaa
// 사용자의 상태를 보고
// 해당 페이지에 들어갈 수 있게 할지 안할지 결정해 줌. hoc 이용.
import
axios
from
'axios'
;
import
React
,
{
useEffect
}
from
'react'
;
//import {useEffect} from 'react';
import
{
useDispatch
}
from
'react-redux'
;
import
{
auth
}
from
'../_actions/user_action'
export
default
function
(
SpecificComponent
,
option
,
adminRoute
=
null
){
// ㄴ option 종류
// - null 아무나 출입 가능한 페이지
// - true 로그인한 유저만 출입 가능
// - false 로그인한 유저 출입 불가능
function
AuthenticationCheck
(
props
)
{
//1. backend에 request를 날려서 사용자의 상태를 확인
const
dispatch
=
useDispatch
();
// 1-1. dispatch 사용
useEffect
(()
=>
{
dispatch
(
auth
())
// 페이지가 이동할 때마다 dispatch가 작동해서 backend에 request를 줌
.
then
(
response
=>
{
// 받은 response
console
.
log
(
response
);
// 로그인 안했다면
if
(
!
response
.
payload
.
isAuth
)
{
if
(
option
)
{
// 만약 위 option이 true이면 (로그인한 유저만 출입 가능한 페이지로 가게 하려면)
props
.
history
.
push
(
'/login'
);
// 로그인 하게 함
}
}
// 로그인 했다면
else
{
if
(
adminRoute
&&
!
response
.
payload
.
isAdmin
)
{
// admin만 갈 수 있는 페이지를 admin이 false 사람이 들어가려 한다면
props
.
history
.
push
(
'/'
);
// 홈페이지로 돌아가게 함
}
else
{
if
(
option
===
false
)
{
// 로그인한 유저가 출입 불가능한 곳을 가려고 한다면
props
.
history
.
push
(
'/'
);
// 홈페이지로 돌아가게 함
}
}
}
})
},[])
return
(
<
SpecificComponent
/>
)
}
return
AuthenticationCheck
}
\ No newline at end of file
boiler-plate
/client/src/index.css
→
We-Shop
/client/src/index.css
View file @
8f8abaa
File moved
boiler-plate
/client/src/index.js
→
We-Shop
/client/src/index.js
View file @
8f8abaa
File moved
boiler-plate
/client/src/reportWebVitals.js
→
We-Shop
/client/src/reportWebVitals.js
View file @
8f8abaa
File moved
boiler-plate
/client/src/setupProxy.js
→
We-Shop
/client/src/setupProxy.js
View file @
8f8abaa
File moved
boiler-plate
/client/src/setupTests.js
→
We-Shop
/client/src/setupTests.js
View file @
8f8abaa
File moved
boiler-plate
/package-lock.json
→
We-Shop
/package-lock.json
View file @
8f8abaa
File moved
boiler-plate
/package.json
→
We-Shop
/package.json
View file @
8f8abaa
File moved
boiler-plate
/server/config/key.js
→
We-Shop
/server/config/key.js
View file @
8f8abaa
File moved
boiler-plate
/server/config/prod.js
→
We-Shop
/server/config/prod.js
View file @
8f8abaa
File moved
boiler-plate
/server/index.js
→
We-Shop
/server/index.js
View file @
8f8abaa
File moved
boiler-plate
/server/middleware/auth.js
→
We-Shop
/server/middleware/auth.js
View file @
8f8abaa
File moved
boiler-plate
/server/models/User.js
→
We-Shop
/server/models/User.js
View file @
8f8abaa
File moved
Please
register
or
login
to post a comment