My android emulator keeps showing this error whenever I try to register new user, Please help me out. I will paste all of these related codes below:
RegisterScreen.js
import React, { useState } from “react”;
import { StyleSheet } from “react-native”;
import * as Yup from “yup”;
import Screen from “…/components/Screen”;
import ErrorMessage from “…/components/forms/ErrorMessage”;
import AppFormField from “…/components/forms/AppFormField”;
import SubmitButton from “…/components/forms/SubmitButton”;
import AppForm from “…/components/forms/AppForm”;
import usersApi from “…/api/users”;
import authApi from “…/api/auth”;
import useApi from “…/hooks/useApi”;
import useAuth from “./…/auth/useAuth”;
import ActivityIndicator from “…/components/ActivityIndicator”;
const validationSchema = Yup.object().shape({
username: Yup.string().required().min(4).label(“Name”),
email: Yup.string().required().email().label(“Email”),
password: Yup.string().required().min(4).label(“Password”),
});
function RegisterScreen(props) {
const registerApi = useApi(usersApi.register);
const loginApi = useApi(authApi.login);
const auth = useAuth();
const [error, setError] = useState();
const handleSubmit = async (userInfo) => {
const result = await registerApi.request(userInfo);
if (!result.ok) {
if (result.data) setError(result.data.error);
else {
setError("An unexpected error occurred.");
console.log(result);
}
return;
}
const { data: authToken } = await authApi.login(
userInfo.email,
userInfo.password
);
auth.logIn(authToken);
};
return (
<>
<ActivityIndicator visible={registerApi.loading || loginApi.loading} />
<Screen style={styles.container}>
<AppForm
initialValues={{ username: "", email: "", password: "" }}
onSubmit={handleSubmit}
validationSchema={validationSchema}
>
<ErrorMessage error={error} visible={error} />
<AppFormField
autoCapitalize="none"
autoCorrect={false}
icon="account"
name="username"
placeholder="Name"
/>
<AppFormField
autoCapitalize="none"
autoCorrect={false}
icon="email"
name="email"
keyboardType="email-address"
placeholder="Email"
textContentType="emailAddress"
/>
<AppFormField
autoCapitalize="none"
autoCorrect={false}
icon="lock"
name="password"
placeholder="Password"
secureTextEntry={true}
/>
<SubmitButton title="REGISTER" />
</AppForm>
</Screen>
</>
);
}
const styles = StyleSheet.create({
container: {
padding: 10,
},
});
export default RegisterScreen;
useApi.js
useAuth.js
client.js
users.js
I tried to console log this error, this is what it shows on the terminal.