php-crud-api icon indicating copy to clipboard operation
php-crud-api copied to clipboard

MultiTenancy - Call to a member function getName() on null

Open Jakan opened this issue 2 years ago • 2 comments

Hi,

I have the following configuration: A "Users" table with columns id, username and password (hash), tenant_id and role.

The following configuration of the api.php

        'address' => 'db',
        'username' => 'username',
        'password' => 'xxxxxxxxxxxx',
        'database' => 'database',
        'middlewares' => 'sanitation,cors,dbAuth,multiTenancy,authorization',
        'cors.allowHeaders' => ("Content-Type, X-XSRF-TOKEN, X-Authorization"),
        'cors.allowCredentials' => 'true',
        'dbAuth.registerUser' => '1',
         'multiTenancy.handler' => function ($operation, $tableName) {
             return ['tenant_id' => $_SESSION['user']['tenant_id']];
        },
        'authorization.tableHandler' => function ($operation, $tableName) {
            return $tableName != 'users';
        },
        'sanitation.handler' => function ($operation, $tableName, $column, $value) {
            return is_string($value) ? strip_tags($value) : $value;
        },
        'debug' => true

If I take out the dbAuth and Authorization, it works and I get the data returned (GET - records/...).

When calling the login route I get the error: POST: https://url/services/api.php/login

{
  "code": 9999,
  "message": "Call to a member function getName() on null"
}

What could be the reason? It runs in a docker container.

Greetings

Jayken

Jakan avatar May 28 '23 11:05 Jakan

I'm really sorry for the late reply, but the response should also contain debug (http) headers, can you post the output of those as well? You can use your favorite tool (or curl i-).

mevdschee avatar Mar 15 '24 07:03 mevdschee

I also just got this error. In my case, the headers indicated line 11239 of the api.include.php file. Taking a look at it, the function was looking for a primary key, and sure enough my table didn't have one set.

Setting a PK cleared the issue.

thetechnician94 avatar Jun 13 '24 17:06 thetechnician94