Toggle navigation
Toggle navigation
This project
Loading...
Sign in
김건희
/
OSSW_Weather_Briefing
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
김건희
2022-05-22 17:22:01 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1f7dfca863f421cd7989b26d7d3042c9df979fdb
1f7dfca8
1 parent
968b2d5c
[Add] Login Redux Setting
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
2 deletions
weather_briefing/src/component/views/LoginPage/LoginPage.js
weather_briefing/src/modules/user.js
weather_briefing/src/component/views/LoginPage/LoginPage.js
View file @
1f7dfca
import
React
,
{
useCallback
,
useState
}
from
"react"
;
import
{
useDispatch
}
from
"react-redux"
;
import
{
login
}
from
"../../../modules/user"
;
import
"../style/LoginPage.scss"
function
LoginPage
(
props
)
{
const
dispatch
=
useDispatch
();
const
[
Id
,
setId
]
=
useState
(
""
);
const
[
Password
,
setPassword
]
=
useState
(
""
);
...
...
@@ -51,12 +54,21 @@ function LoginPage(props) {
setCheckLoginError
(
false
);
}
// login
data
// login
if
(
!
checkLoginError
)
{
const
UserData
=
{
id
:
Id
,
password
:
Password
,
};
dispatch
(
login
(
UserData
))
.
then
(
res
=>
{
if
(
res
.
payload
.
logged
)
{
props
.
history
.
push
(
'/register'
);
}
else
{
alert
(
res
.
payload
.
error
);
}
})
}
},
[
checkIdError
,
checkPasswordError
,
Password
]);
...
...
weather_briefing/src/modules/user.js
View file @
1f7dfca
import
axios
from
'axios'
;
const
REGISTER
=
'user/REGISTER'
;
const
LOGIN
=
'user/LOGIN'
const
InitialState
=
{
logged
:
false
,
name
:
'test'
,
id
:
'test123'
,
password
:
'test1111~'
,
...
...
@@ -19,11 +21,24 @@ export function register(data) {
}
};
export
function
login
(
data
)
{
const
req
=
axios
.
post
(
'http://localhost:4000/login'
,
data
)
.
then
(
res
=>
res
.
date
);
return
{
type
:
LOGIN
,
payload
:
req
,
}
};
export
default
function
(
state
=
InitialState
,
action
)
{
switch
(
action
.
type
)
{
case
REGISTER
:
return
{...
state
,
register
:
action
.
payload
};
break
;
case
LOGIN
:
return
{...
state
,
logged
:
action
.
payload
};
break
;
default
:
return
state
;
}
...
...
Please
register
or
login
to post a comment