I am building web app using PHP and i got this error from swagger when making auth for login to my app.
Cannot access offset of type string on string (0).
Here is the code for the route
/**
* @OAPost(
* path=”/auth/login”,
* tags={“auth”},
* summary=”Login to system using email and password”,
* @OAResponse(
* response=200,
* description=”User data and JWT”
* ),
* @OARequestBody(
* description=”Credentials”,
* @OAJsonContent(
* required={“email”,”pwd”},
* @OAProperty(property=”email”, type=”string”, example=”[email protected]”, description=”User email address”),
* @OAProperty(property=”pwd”, type=”string”, example=”some_password”, description=”User password”)
* )
* )
* )
*/
Flight::route(‘POST /login’, function() {
$payload = Flight::request()->data->getData();
var_dump($payload);
$user = Flight::get('auth_service')->get_user_by_email($payload['email']);
var_dump($user);
if(!$user || !password_verify($payload['pwd'], $user['pwd']))
Flight::halt(500, "Invalid username or password");
unset($user['pwd']);
});
I have double checked all methods in service and dao but can’t find the solution. Thanks a lot for any responses.
Tried var_dump() but got same error when using it.
Amir Bašović is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.