I am looking to make an API call from a React Native application. I am trying to figure out why I am getting a Network Error. I send the POST request from the app using AXIOS, also I have Sanctum set up to get token for user to be able to register and login. When I try to register Back from Server, ERROR & NETWORK ERROR is logged in the console as you can see below in my console.log calls. My code for both register on the React native app and register from Laravel app are below. Any help would be amazing!
`public function registerSanctum (Request $request) {
info($request->info());
$fields = $request->validate([
'email' => 'required|unique:user,email',
'password' => 'required'
]);
$user = User::create([
'email' => $fields['email'],
'password' => bcrypt($fields['password'])
]);
$token = $user->createToken('registerAppToken')->plainTextToken;
$response = [
'user' => $user,
'token' => $token
];
return response($response);
}`
React Native
export const login = (email, password) => (dispatch) => new Promise((resolve, reject) => { axios .post(
${LOGIN}`, {
'email': email,
'password': password,
})
.then(function (response) {
navigation.navigate("feed");
// 2 seconds later...
console.log("------------ Response XXX ---------");
// console.log(response);
console.log(response.data);
console.log("------------ Response XXX ---------");
})
.catch(function (error) {
console.log("------------ Back from Server ----------");
console.log("------------ ERROR -------------");
console.log(error);
});
});`
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community