update login and verify otp

This commit is contained in:
Jaanu423
2025-09-15 11:18:39 +05:30
parent a26b6f5e7a
commit 737c3a486e
4 changed files with 545 additions and 179 deletions
+9 -8
View File
@@ -14,10 +14,11 @@ import {
KeyboardAvoidingView,
StatusBar,
Alert,
ToastAndroid,
} from "react-native";
import { RootStackParamList } from "../navigation/AppNavigator";
import * as Keychain from "react-native-keychain";
import { LOGIN_URL } from "../utils/ApiUrls";
import { base_URL, LOGIN_URL } from "../utils/ApiUrls";
import { StackNavigationProp } from "@react-navigation/stack";
const theme = {
@@ -76,7 +77,7 @@ export default function OtpVerificationScreen() {
try {
const payload = { mobile, otp };
const res = await axios.post(
"https://exotic-humpback-mistakenly.ngrok-free.app/api/user/otp/verify",
`${base_URL}user/otp/verify`,
payload,
{ headers: { "Content-Type": "application/json", Accept: "*/*" } }
);
@@ -85,11 +86,10 @@ export default function OtpVerificationScreen() {
if (res.data.statusCode === 200) {
saveToken(res.data.data);
navigation.navigate('Home')
}
ToastAndroid.show("OTP Verified Successfully!", ToastAndroid.SHORT);}
} catch (err: any) {
console.error("❌ OTP Verification Error:", err?.response?.data || err.message);
Alert.alert("Error", "Failed to verify OTP. Please try again.");
ToastAndroid.show(err.message || "Invalid OTP. Please try again.", ToastAndroid.SHORT);
}
};
@@ -104,11 +104,12 @@ export default function OtpVerificationScreen() {
);
console.log("📩 OTP Resent:", res.data);
Alert.alert("OTP Sent", "A new OTP has been sent to your mobile.");
setCode(Array(CELL_COUNT).fill(""));
inputs.current[0]?.focus();
ToastAndroid.show("OTP Sent", ToastAndroid.SHORT);
} catch (err: any) {
console.error("❌ Resend OTP Error:", err?.response?.data || err.message);
Alert.alert("Error", "Failed to resend OTP. Try again later.");
ToastAndroid.show("Failed to resend OTP. Try again later.", ToastAndroid.SHORT);
} finally {
setIsResending(false);
}