diff --git a/src/screens/AuthScreen.tsx b/src/screens/AuthScreen.tsx index 8d8dff6..fc29be3 100644 --- a/src/screens/AuthScreen.tsx +++ b/src/screens/AuthScreen.tsx @@ -1,6 +1,8 @@ import { Alert, Image, + KeyboardAvoidingView, + Platform, StatusBar, StyleSheet, Text, @@ -21,7 +23,6 @@ import Ionicons from 'react-native-vector-icons/Ionicons' import { Dimensions } from 'react-native' import OTPInputView from '@twotalltotems/react-native-otp-input' import emailSchema from '../validation/zod' -import axios from 'axios' import AuthService from '../services' const windowHeight = Dimensions.get('window').height @@ -33,38 +34,50 @@ const AuthScreen = () => { const [mail, setMail] = useState('') const [validationMail, setValidationMail] = useState(false) const [code, setCode] = useState('') + const [isLoading, setIsLoading] = useState(false) const handleMailChange = (text: string) => { setMail(text) } const handleValidateEmail = async () => { + setIsLoading(true) try { emailSchema.parse(mail); + const response = await AuthService.sendLoginOTP(mail); - if (response.status === 200) { + if (response.status === 9999) { + setIsLoading(false) setValidationMail(true); } else { + setIsLoading(false) Alert.alert('Something Unwanted happened'); } } catch (error:any) { + setIsLoading(false) Alert.alert('Error', error.message || 'Something went wrong'); } }; const VerifyOtp = async () => { + setIsLoading(true) try { const response = await AuthService.verifyLoginOTP(mail, code); - if (response.status === 200) { + if (response===true) { + setIsLoading(false) userAuthentication(); } else { + setIsLoading(false) Alert.alert('Wrong Otp'); } } catch (error) { + setIsLoading(false) Alert.alert('Something Went wrong'); } }; return ( - + { {validationMail ? ( - Verify + {isLoading?'Processing...':'Verify'} ) : ( - Continue + {isLoading?'Processing...':'Continue'} )} @@ -126,7 +139,7 @@ const AuthScreen = () => { ) : null} - + ) } diff --git a/src/services/index.ts b/src/services/index.ts new file mode 100644 index 0000000..b59a006 --- /dev/null +++ b/src/services/index.ts @@ -0,0 +1,27 @@ +import axios from 'axios'; + +const baseURL = ' http://localhost:5000'; + +const AuthService = { + sendLoginOTP: async (email:string) => { + try { + const {data} = await axios.get(`${baseURL}/login-otp/${email}`); + + return data; + } catch (error) { + throw error; + } + }, + + verifyLoginOTP: async (email:string, token:string) => { + try { + const {data} = await axios.get(`${baseURL}/verify-login-otp/${email}/${token}`); + + return data; + } catch (error) { + throw error; + } + }, +}; + +export default AuthService; diff --git a/src/validation/zod.ts b/src/validation/zod.ts index 76a8579..d184d42 100644 --- a/src/validation/zod.ts +++ b/src/validation/zod.ts @@ -2,4 +2,5 @@ import { z } from 'zod'; const emailSchema = z.string().email(); + export default emailSchema \ No newline at end of file