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 = { 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;

View File

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

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