The error message suggests that the response from the authentication route is not valid JSON. One possible reason for this could be that the response is not being returned as JSON, or that there is an error in the JSON encoding.
To debug this issue, you can try logging the response from the authentication route to see what it contains. You can also try using a tool like Postman to send a request to the authentication route and inspect the response.
Assuming that the response is indeed invalid JSON, one possible solution is to ensure that the response is returned as valid JSON. In the code provided, the response is being returned as an array, which is then converted to JSON using the response()->json() method. However, this method expects an array or an object as input, and not a string.
To fix this, you can try returning the response as an object instead of an array, like this:
return response()->json([
'channel_data' => [
'user_id' => $user_id,
'user_name' => $user_name,
'signature' => $signature
]
]);
Alternatively, you can try encoding the array as JSON manually using the json_encode() function, like this:
return response(json_encode([
'channel_data' => [
'user_id' => $user_id,
'user_name' => $user_name,
'signature' => $signature
]
]))->header('Content-Type', 'application/json');
This should ensure that the response is returned as valid JSON, which should resolve the error.