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(() => { useEffect(() => {
if (!loginMutation.data) return; if (!loginMutation.data) {
if (Object.hasOwn(loginMutation.data.login, "message")) {
setSubmitError(loginMutation.data.login.message);
return; return;
} } else if (loginMutation.data.login.__typename == "CommonError") {
if (Object.hasOwn(loginMutation.data.login, "token")) { setSubmitError(loginMutation.data.login.message);
} else if (loginMutation.data.login.__typename == "AuthSuccess") {
localStorage.setItem("token", loginMutation.data.login.token); localStorage.setItem("token", loginMutation.data.login.token);
navigator("/services"); navigator("/services");
} }

View File

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