connect login with backend
This commit is contained in:
parent
8b21daa230
commit
06be312d8c
|
@ -39,12 +39,12 @@ const LoginUserScreen = ({navigation}) => {
|
|||
});
|
||||
};
|
||||
|
||||
const register = async () => {
|
||||
const login_user = async () => {
|
||||
var data = {
|
||||
username: username,
|
||||
orgName: orgname,
|
||||
email: username,
|
||||
password: password,
|
||||
};
|
||||
await fetch('http://192.168.29.141:4000/users', {
|
||||
await fetch('http://192.168.29.141:5000/users/login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
|
@ -63,10 +63,12 @@ const LoginUserScreen = ({navigation}) => {
|
|||
'\n data success',
|
||||
response_data.success + typeof response_data.success,
|
||||
);
|
||||
if (response_data.success) {
|
||||
if (response_data.token) {
|
||||
await setKey('token', response_data.token);
|
||||
setToken(response_data.token);
|
||||
setMessage(response_data.message);
|
||||
setMessage('user ' + response_data.user.username + ' logged in');
|
||||
} else {
|
||||
setMessage(response_data.msg);
|
||||
}
|
||||
var key_token = await getKey('token');
|
||||
console.log('retrived key_token ' + key_token);
|
||||
|
@ -83,7 +85,7 @@ const LoginUserScreen = ({navigation}) => {
|
|||
style: isPress ? styles.btnPress : styles.btnNormal,
|
||||
onHideUnderlay: () => setIsPress(false),
|
||||
onShowUnderlay: () => setIsPress(true),
|
||||
onPress: register,
|
||||
onPress: login_user,
|
||||
};
|
||||
|
||||
var textInputProps = {
|
||||
|
@ -126,9 +128,9 @@ const LoginUserScreen = ({navigation}) => {
|
|||
<Text {...inputHeadingProps}>Password</Text>
|
||||
<TextInput
|
||||
{...textInputProps}
|
||||
value={orgname}
|
||||
placeholder="Name of the organization"
|
||||
onChangeText={setOrgname}
|
||||
value={password}
|
||||
placeholder="enter the password"
|
||||
onChangeText={setPassword}
|
||||
/>
|
||||
</View>
|
||||
|
||||
|
@ -146,16 +148,15 @@ const LoginUserScreen = ({navigation}) => {
|
|||
{message ? (
|
||||
<Text style={{color: '#206ba5', fontSize: 25}}>{message}</Text>
|
||||
) : (
|
||||
<Text style={{color: 'red', fontSize: 25}}>
|
||||
{error.message}
|
||||
</Text>
|
||||
<Text style={{color: 'red', fontSize: 25}}>{error.message}</Text>
|
||||
)}
|
||||
<View>
|
||||
<Text style={{color: '#206ba5', fontSize: 15, textAlign:'left'}}
|
||||
onPress={() => navigation.navigate('RegisterUserScreen')}>
|
||||
Not a member yet?
|
||||
<View>
|
||||
<Text
|
||||
style={{color: '#206ba5', fontSize: 15, textAlign: 'left'}}
|
||||
onPress={() => navigation.navigate('RegisterUserScreen')}>
|
||||
Not a member yet?
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
|
@ -174,7 +175,7 @@ const styles = StyleSheet.create({
|
|||
textAlign: 'center',
|
||||
fontFamily: 'Ubuntu-Bold',
|
||||
},
|
||||
|
||||
|
||||
icon: {
|
||||
alignSelf: 'flex-start',
|
||||
marginLeft: '28%',
|
||||
|
@ -218,5 +219,4 @@ const styles = StyleSheet.create({
|
|||
},
|
||||
});
|
||||
|
||||
|
||||
export default LoginUserScreen;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
"react-native-gesture-handler": "^1.10.3",
|
||||
"react-native-reanimated": "^2.2.0",
|
||||
"react-native-safe-area-context": "^3.2.0",
|
||||
"react-native-screens": "^3.13.1",
|
||||
"react-native-screens": "3.3.0",
|
||||
"react-native-sensitive-info": "^6.0.0-alpha.9",
|
||||
"react-native-vector-icons": "^8.1.0"
|
||||
},
|
||||
|
|
|
@ -6364,7 +6364,12 @@ react-native-safe-area-context@^3.2.0:
|
|||
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-3.4.1.tgz#c967a52903d55fe010b2428e5368b42f1debc0a7"
|
||||
integrity sha512-xfpVd0CiZR7oBhuwJ2HcZMehg5bjha1Ohu1XHpcT+9ykula0TgovH2BNU0R5Krzf/jBR1LMjR6VabxdlUjqxcA==
|
||||
|
||||
react-native-screens@^3.11.1, react-native-screens@^3.13.1:
|
||||
react-native-screens@3.3.0:
|
||||
version "3.3.0"
|
||||
resolved "https://registry.yarnpkg.com/react-native-screens/-/react-native-screens-3.3.0.tgz#d4464a96620b85d09e46bd6865b5f48456c244f0"
|
||||
integrity sha512-ni11jC6I9cFVXdLIDwkgafDHw/STXUNzkR5Fx3w8Wikdzi8gfTEan2kiOm7aS42d2F/LXddZ6i74Z2em0L6LPQ==
|
||||
|
||||
react-native-screens@^3.11.1:
|
||||
version "3.13.1"
|
||||
resolved "https://registry.yarnpkg.com/react-native-screens/-/react-native-screens-3.13.1.tgz#b3b1c5788dca25a71668909f66d87fb35c5c5241"
|
||||
integrity sha512-xcrnuUs0qUrGpc2gOTDY4VgHHADQwp80mwR1prU/Q0JqbZN5W3koLhuOsT6FkSRKjR5t40l+4LcjhHdpqRB2HA==
|
||||
|
|
Loading…
Reference in New Issue