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