Leveraging __typename for login API response

This commit is contained in:
strNophix 2022-06-19 22:38:46 +02:00
parent 61154028a3
commit c5308eb430
2 changed files with 5 additions and 5 deletions

View File

@ -22,12 +22,11 @@ const LoginPage = () => {
});
useEffect(() => {
if (!loginMutation.data) return;
if (Object.hasOwn(loginMutation.data.login, "message")) {
setSubmitError(loginMutation.data.login.message);
if (!loginMutation.data) {
return;
}
if (Object.hasOwn(loginMutation.data.login, "token")) {
} else if (loginMutation.data.login.__typename == "CommonError") {
setSubmitError(loginMutation.data.login.message);
} else if (loginMutation.data.login.__typename == "AuthSuccess") {
localStorage.setItem("token", loginMutation.data.login.token);
navigator("/services");
}

View File

@ -1,5 +1,6 @@
mutation Login($credentials: LoginInput!) {
login(body: $credentials) {
__typename
... on AuthSuccess {
user {
name