Toggle navigation
Toggle navigation
This project
Loading...
Sign in
오인제
/
Tunnel
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
정의왕
2021-12-09 02:08:32 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b342c6ded7ab04d55a9ccb55669eae175b656e6c
b342c6de
1 parent
4bff8cee
Complete Auth routing
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
23 additions
and
33 deletions
tunnel_BE/server/routes/auth.js
tunnel_BE/server/routes/logout.js
tunnel_BE/server/routes/register.js
turnel_FE/src/App.js
turnel_FE/src/component/views/LoginPage/LoginPage.js
turnel_FE/src/component/views/MainPage/MainPage.js
turnel_FE/src/component/views/RegisterPage/RegisterPage.js
turnel_FE/src/hoc/auth.js
tunnel_BE/server/routes/auth.js
View file @
b342c6d
...
...
@@ -2,11 +2,9 @@ const express = require("express");
const
bodyParser
=
require
(
"body-parser"
);
const
router
=
express
.
Router
();
router
.
get
(
'/'
,(
req
,
res
)
=>
{
if
(
req
.
session
.
name
!=
null
&&
req
.
session
.
name
!=
undefined
){
console
.
log
(
"req.session.name"
);
console
.
log
(
req
.
session
.
name
);
res
.
sendStatus
(
200
);
}
else
{
...
...
@@ -14,8 +12,4 @@ router.get('/',(req,res)=>{
res
.
sendStatus
(
401
);
}
});
module
.
exports
=
router
;
\ No newline at end of file
...
...
tunnel_BE/server/routes/logout.js
View file @
b342c6d
...
...
@@ -10,7 +10,6 @@ router.get('/',(req,res)=>{
//로그아웃
router
.
post
(
'/'
,(
req
,
res
)
=>
{
if
(
result
.
dataValues
.
pw
==
req
.
body
.
Password
){
req
.
session
.
id
=
null
;
req
.
session
.
name
=
null
;
req
.
session
.
personality
=
null
;
...
...
@@ -18,7 +17,6 @@ router.post('/',(req,res)=>{
req
.
session
.
isAuthorized
=
null
;
console
.
log
(
"Logout"
);
res
.
sendStatus
(
200
);
}
})
})
module
.
exports
=
router
;
\ No newline at end of file
...
...
tunnel_BE/server/routes/register.js
View file @
b342c6d
...
...
@@ -41,7 +41,4 @@ router.get("/:id",(req,res)=>{
console
.
log
(
req
.
params
,
req
.
query
);
req
.
body
;
});
module
.
exports
=
router
;
\ No newline at end of file
...
...
turnel_FE/src/App.js
View file @
b342c6d
...
...
@@ -5,21 +5,18 @@ import LoginPage from "./component/views/LoginPage/LoginPage";
import
RegisterPage
from
"./component/views/RegisterPage/RegisterPage"
;
import
"./static/fonts/font.css"
;
import
Auth
from
'./hoc/auth'
;
function
App
()
{
return
(
<
Router
>
<
div
>
<
Routes
>
<
Route
exact
path
=
"/"
element
=
{
Auth
(
LoginPage
,
false
)}
/>
<
Route
exact
path
=
"/login"
element
=
{
Auth
(
LoginPage
,
false
)}
/>
<
Route
exact
path
=
"/main"
element
=
{
Auth
(
MainPage
,
true
)}
/
>
<
Route
exact
path
=
"/login"
element
=
{
Auth
(
LoginPage
,
false
)}
>
<
/Route
>
<
Route
exact
path
=
"/register"
element
=
{
Auth
(
RegisterPage
,
false
)}
>
<
/Route
>
<
Route
exact
path
=
"/register"
element
=
{
Auth
(
RegisterPage
,
false
)}
/
>
<
/Routes
>
<
/div
>
<
/Router
>
);
}
export
default
App
;
\ No newline at end of file
...
...
turnel_FE/src/component/views/LoginPage/LoginPage.js
View file @
b342c6d
...
...
@@ -3,7 +3,6 @@ import "../style/LoginPage.scss";
import
Axios
from
'axios'
import
{
Icon
,
Input
}
from
"semantic-ui-react"
import
{
useNavigate
}
from
"react-router-dom"
;
function
LoginPage
()
{
let
navigate
=
useNavigate
();
const
[
Id
,
setId
]
=
useState
(
""
);
...
...
turnel_FE/src/component/views/MainPage/MainPage.js
View file @
b342c6d
import
{
Button
}
from
"semantic-ui-react"
import
Axios
from
'axios'
import
"../style/MainPage.scss"
;
import
{
useNavigate
}
from
"react-router-dom"
;
import
{
CKEditor
}
from
'@ckeditor/ckeditor5-react'
;
import
ClassicEditor
from
'@ckeditor/ckeditor5-build-classic'
;
function
MainPage
(
props
)
{
const
isLogin
=
props
.
isLogin
;
const
navigate
=
useNavigate
();
const
onLogout
=
()
=>
{
// sessionStorage 에 user_id 로 저장되어있는 아이템을 삭제한다.
sessionStorage
.
removeItem
(
'isAuthorized'
)
// App 으로 이동(새로고침)
navigate
(
'/login'
);
Axios
.
post
(
'/api/logout'
)
.
then
((
res
)
=>
{
if
(
res
.
status
===
200
){
alert
(
"성공적으로 로그아웃하였습니다."
)
navigate
(
'/login'
)
}
})
// App 으로 이동(새로고침)
}
return
(
<
div
id
=
"Main"
>
...
...
@@ -96,5 +99,4 @@ function MainPage(props) {
<
/div
>
);
}
export
default
MainPage
;
\ No newline at end of file
...
...
turnel_FE/src/component/views/RegisterPage/RegisterPage.js
View file @
b342c6d
...
...
@@ -3,14 +3,12 @@ import { useNavigate } from "react-router-dom";
import
"../style/RegisterPage.scss"
;
import
{
Button
,
Icon
,
Input
}
from
"semantic-ui-react"
;
import
Axios
from
'axios'
function
RegisterPage
(
props
)
{
const
navigate
=
useNavigate
();
const
[
Id
,
setId
]
=
useState
(
""
);
const
[
Password
,
setPassword
]
=
useState
(
""
);
const
[
PasswordCheck
,
setPasswordCheck
]
=
useState
(
""
);
const
[
Personality
,
setPersonality
]
=
useState
(
""
);
const
onIdHandler
=
(
event
)
=>
{
setId
(
event
.
currentTarget
.
value
);
};
...
...
turnel_FE/src/hoc/auth.js
View file @
b342c6d
import
React
,
{
useEffect
}
from
'react'
;
import
Axios
from
'axios'
;
import
{
useNavigate
}
from
'react-router-dom'
;
export
default
function
(
SpecificComponent
)
{
export
default
function
(
SpecificComponent
,
option
,
adminRoute
=
null
)
{
// option
// null -> 아무나 출입, true -> 로그인한 유저만 출입, false -> 로그인한 유저는 출입 불가능
function
AuthenticationCheck
()
{
...
...
@@ -9,13 +9,18 @@ export default function (SpecificComponent) {
useEffect
(()
=>
{
Axios
.
get
(
'/api/auth'
)
.
then
((
res
)
=>
{
if
(
res
.
status
===
200
){
if
(
res
.
status
===
200
&&
adminRoute
){
navigate
(
'/main'
)
}
else
{
if
(
option
===
false
){
navigate
(
'/main'
)
}
}
}).
catch
((
error
)
=>
{
console
.
log
(
error
.
response
);
alert
(
'로그인이 필요합니다!'
);
navigate
(
'/login'
);
if
(
option
){
navigate
(
'/login'
)
}
})
},
[])
...
...
Please
register
or
login
to post a comment