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-11 18:48:55 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
203c166087d2465be9888e5b97a564c9844ce6b6
203c1660
1 parent
68c88887
update Auth Queries and useMutation hook
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
34 deletions
front/src/Routes/Auth/AuthContainer.js
front/src/Routes/Auth/AuthQueries.js
front/src/Routes/Auth/AuthContainer.js
View file @
203c166
...
...
@@ -15,40 +15,36 @@ export default () => {
const
username
=
useInput
(
""
);
// mutations
const
loginMutation
=
useMutation
(
LOGIN
,
{
variables
:
{
email
:
email
.
value
,
password
:
password
.
value
},
});
const
[
login
]
=
useMutation
(
LOGIN
);
const
createAccountMutation
=
useMutation
(
SIGNUP
,
{
variables
:
{
email
:
email
.
value
,
username
:
username
.
value
,
password
:
password
.
value
,
password2
:
password2
.
value
,
phoneNum
:
phoneNum
.
value
,
},
});
const
[
createAccount
]
=
useMutation
(
SIGNUP
);
// TODO:
make login success query.
// TODO:
When login or signup success, get token from mutation function
let
Auth
;
let
token
;
const
onSubmit
=
async
(
e
)
=>
{
e
.
preventDefault
();
if
(
action
===
"logIn"
)
{
if
(
email
.
value
!==
""
)
{
try
{
// QL 을 통해서 data 를 가져온다.
const
{
data
:
{
login
},
// AuthQueries 에 정의된 mutation 값
}
=
await
loginMutation
();
if
(
!
login
)
{
Auth
=
await
login
({
variables
:
{
email
:
email
.
value
,
password
:
password
.
value
},
});
token
=
Auth
.
data
.
login
.
token
;
if
(
!
Auth
)
{
// when login fail
toast
.
warn
(
"you need to make your own account"
);
setAction
(
"signUp"
);
}
else
{
// when login success
toast
.
success
(
"login success"
);
setAction
(
"confirm"
);
// TODO: move page to Main container.
}
}
catch
{
toast
.
error
(
"login failed!"
);
}
}
catch
(
e
)
{}
}
else
{
// TODO: inform "email is required" using toastify
toast
.
error
(
"email is required!"
,
{
position
:
"top-center"
,
autoClose
:
3000
,
...
...
@@ -65,26 +61,29 @@ export default () => {
phoneNum
.
value
!==
""
)
)
{
try
{
const
{
data
:
{
signUp
},
}
=
await
createAccountMutation
();
if
(
!
signUp
)
{
Auth
=
await
createAccount
({
variables
:
{
email
:
email
.
value
,
username
:
username
.
value
,
password
:
password
.
value
,
password2
:
password2
.
value
,
phoneNum
:
phoneNum
.
value
,
},
});
token
=
Auth
.
data
.
createAccount
.
token
;
if
(
!
Auth
)
{
toast
.
warn
(
"you need to sign up first"
);
setAction
(
"signUp"
);
}
else
{
toast
.
success
(
"login success"
);
setAction
(
"logIn"
);
}
}
catch
(
e
)
{
// TODO: can't find data: signUp
}
catch
{
toast
.
error
(
"can't sign up, please check input data"
);
}
}
else
{
// TODO: inform user need to input values that required for sign up with toastify
toast
.
error
(
"you need to input with vaild data"
);
}
}
else
if
(
action
===
"confirm"
)
{
// TODO: when login success, go to Main Container
}
};
...
...
front/src/Routes/Auth/AuthQueries.js
View file @
203c166
...
...
@@ -2,24 +2,34 @@ import { gql } from "apollo-boost";
export
const
LOGIN
=
gql
`
mutation login($email: String!, $password: String!) {
login(email: $email, password: $password)
login(email: $email, password: $password) {
token
user {
id
}
}
}
`
;
export
const
SIGNUP
=
gql
`
mutation
signUp
(
mutation
createAccount
(
$email: String!
$username: String!
$password: String!
$password2: String!
$phoneNum: String!
) {
signUp
(
createAccount
(
email: $email
username: $username
password: $password
password2: $password2
phoneNum: $phoneNum
)
) {
token
user {
id
}
}
}
`
;
...
...
Please
register
or
login
to post a comment