Support the ongoing development of Laravel.io →
React Laravel

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);
  });

});`

Last updated by @blackholecoder 3 years ago.
0

What is the status of the error? Is it 500?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.