Skip to content

Commit

Permalink
resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sim1029 committed Mar 1, 2022
2 parents 0ae4b05 + 0c4679b commit 7c63415
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 38 deletions.
42 changes: 18 additions & 24 deletions components/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import useToken from "./useToken";
import localData from "./localData";

const Login = ({navigation}) => {
const [email, setEmailHook] = useState("[email protected]");
const [password, setPasswordHook] = useState("pass");
const [email, setEmailHook] = useState("");
const [password, setPasswordHook] = useState("");
const {setToken} = useToken();
const {setUserId, setUserName, setGroupId, setEmail, setPassword, getEmail, getPassword} = localData();
const {setUserId, setUserName, setGroupId, setEmail, setPassword, getEmail, getPassword, getUserName} = localData();

// useEffect(() => {
// getEmail().then((email) => {
Expand All @@ -25,7 +25,7 @@ const Login = ({navigation}) => {
// }, [])

const loginUser = async () => {
fetch('https://easygrocy.com/api/auth/login', {
await fetch('https://easygrocy.com/api/auth/login', {
method: "POST",
headers: {
Accept: 'application/json',
Expand All @@ -40,44 +40,38 @@ const Login = ({navigation}) => {
if(!response.ok) throw new Error(response.status);
else return response.json();
})
.then((json) => {
setToken(json.access_token).then(() => {
setUserId("" + json.user_id).then(() => {
getUserGroups("" + json.user_id, json.access_token).then(() => {
setEmail(email).then(() => {
setPassword(password).then(() => {
getUserName("" + json.user_id, json.access_token).then(() => {
navigation.navigate("GrocyStack");
});
});
});
});
});
});
.then( async (json) => {
await setToken(json.access_token)
await setUserId("" + json.user_id)
await getUserGroups("" + json.user_id, json.access_token)
await setEmail(email)
await setPassword(password)
await getUserNameEndpoint("" + json.user_id, json.access_token)
navigation.navigate("GrocyStack");
})
.catch((error) => console.error(error));
}

const getUserGroups = async (userId, token) => {
fetch(`https://easygrocy.com/api/user/${userId}/groups`, {
await fetch(`https://easygrocy.com/api/user/${userId}/groups`, {
method: "GET",
headers: {'Authorization': 'Bearer ' + token}
})
.then((response) => {
if(!response.ok) throw new Error(response.status)
else return response.json();
})
.then((json) => {
.then(async (json) => {
const groups = json.groups;
if (groups.length > 0) {
setGroupId("" + groups[0].id);
setGroupName(groups[0].name);
await setGroupId("" + groups[0].id);
await setGroupName(groups[0].name);
}
})
}

const getUserName = async (userId, token) => {
fetch(`https://easygrocy.com/api/user/${userId}`, {
const getUserNameEndpoint = async (userId, token) => {
await fetch(`https://easygrocy.com/api/user/${userId}`, {
method: "GET",
headers: {'Authorization': 'Bearer ' + token}
})
Expand Down
23 changes: 9 additions & 14 deletions components/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const Signup = ({navigation}) => {
const {setToken} = useToken();
const {setUserId, setUserName, setEmail, setPassword} = localData();

const signUpUser = () => {
fetch('https://easygrocy.com/api/auth/register', {
const signUpUser = async () => {
await fetch('https://easygrocy.com/api/auth/register', {
method: "POST",
headers: {
Accept: 'application/json',
Expand All @@ -34,18 +34,13 @@ const Signup = ({navigation}) => {
if(!response.ok) throw new Error(response.status);
else return response.json();
})
.then((json) => {
setToken(json.access_token).then(() => {
setUserName(username).then(() => {
setUserId("" + json.user_id).then(() => {
setEmail(email).then(() => {
setPassword(password).then(() => {
navigation.navigate("GrocyStack");
})
})
})
})
})
.then(async (json) => {
await setToken(json.access_token)
await setUserName(username)
await setUserId("" + json.user_id)
await setEmail(email)
await setPassword(password)
navigation.navigate("GrocyStack");
})
.catch((error) => console.error(error))
}
Expand Down

0 comments on commit 7c63415

Please sign in to comment.