Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design1
/
Triz_Project1
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
1
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
sdy
2020-05-13 01:34:04 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b8fffeeeb05e62ff46255518d25dea8f8d2834f8
b8fffeee
1 parent
9bec9fec
update AuthContainer.js
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
front/src/Routes/Auth/AuthContainer.js
front/src/Routes/Auth/AuthContainer.js
View file @
b8fffee
import
React
,
{
useState
}
from
"react"
;
import
{
useMutation
}
from
"@apollo/react-hooks"
;
import
{
LOGIN
,
SIGNUP
}
from
"./AuthQueries"
;
import
{
LOGIN
,
SIGNUP
,
LOCAL_LOG_IN
}
from
"./AuthQueries"
;
import
useInput
from
"../../Hooks/useInput"
;
import
{
toast
}
from
"react-toastify"
;
import
AuthPresenter
from
"./AuthPresenter"
;
...
...
@@ -14,15 +14,12 @@ export default () => {
const
phoneNum
=
useInput
(
""
);
const
username
=
useInput
(
""
);
// mutations
const
[
login
]
=
useMutation
(
LOGIN
);
const
[
createAccount
]
=
useMutation
(
SIGNUP
);
const
[
loginState
]
=
useMutation
(
LOCAL_LOG_IN
);
// TODO: When login or signup success, get token from mutation function
let
Auth
;
let
token
;
let
Auth
;
// mutation result variable
let
token
;
// token from login or signUp.
const
onSubmit
=
async
(
e
)
=>
{
e
.
preventDefault
();
if
(
action
===
"logIn"
)
{
...
...
@@ -30,7 +27,7 @@ export default () => {
try
{
Auth
=
await
login
({
variables
:
{
email
:
email
.
value
,
password
:
password
.
value
},
});
});
// AuthPayload object.
token
=
Auth
.
data
.
login
.
token
;
if
(
!
Auth
)
{
// when login fail
...
...
@@ -38,8 +35,11 @@ export default () => {
setAction
(
"signUp"
);
}
else
{
// when login success
console
.
log
(
"login success"
);
toast
.
success
(
"login success"
);
// TODO: move page to Main container.
await
loginState
({
variables
:
{
token
},
});
}
}
catch
{
toast
.
error
(
"login failed!"
);
...
...
Please
register
or
login
to post a comment