connect login with backend

This commit is contained in:
Priyatham Sai chand 2022-05-10 09:11:06 +05:30
parent 8b21daa230
commit 06be312d8c
No known key found for this signature in database
GPG Key ID: C3DFD0A2F6675222
3 changed files with 27 additions and 22 deletions

View File

@ -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;

View File

@ -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"
},

View File

@ -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==