Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems to use custom users table name #952

Closed
chattago2002 opened this issue Jan 24, 2023 · 5 comments
Closed

Problems to use custom users table name #952

chattago2002 opened this issue Jan 24, 2023 · 5 comments
Assignees
Labels

Comments

@chattago2002
Copy link

Hi.

I love your repository and I'm using it in many different projects.
For the last one I downloaded last version v2.14.16 but I have problems with my custom table name for apiKeyDbAuth.usersTable and dbAuth.usersTable. I want to use my custom table name instead of "users".
In a older version (I think is v2.14.6 ) there is no problem while in the last one I have many problems (i.e. sometimes debug says error 9999) and it seems to work fine when I rename the table in "users".

Am I wrong in something?

@mevdschee mevdschee self-assigned this Jan 25, 2023
@mevdschee
Copy link
Owner

Hi, thank you for creating this issue. I'm not aware of any breaking changes. Can you share your config? Ideally a minimal example with config and request that fails.

@chattago2002
Copy link
Author

chattago2002 commented Jan 30, 2023

Hi.
Here is my config:

$config = new Config([
    'driver' => 'mysql',
    'address' => 'localhost',
    'port' => '3306',
    'username' => 'db_user',
    'password' => 'db_pwd',
    'database' => 'db_name',
    'middlewares' => 'cors, dbAuth, apiKeyDbAuth, authorization',
    'debug' => true,
    'apiKeyDbAuth.mode' => 'required',
    'apiKeyDbAuth.header' => 'X-API-Key',
    'apiKeyDbAuth.usersTable' => 'utente',
    'apiKeyDbAuth.apiKeyColumn' => 'api_key',
    'cors.allowedOrigins' => 'http://localhost:3000, https://mydomain.com',
    'dbAuth.mode' => 'optional',
    'dbAuth.usersTable' => 'utenti_attivi',
    'dbAuth.usernameColumn' => 'email',
    'dbAuth.passwordColumn' => 'hashed_pwd',
    'dbAuth.usernameFormField' => 'username',
    'dbAuth.passwordFormField' => 'password',
    'dbAuth.registerUser' => true,
    'dbAuth.passwordLength' => '8',
    'authorization.recordHandler' => function ($operation, $tableName) {
        if ($_SESSION['apiUser']['id_ruolo'] != 1) {
            if ($tableName === 'utente') {
                return ($tableName == 'utente') ? 'filter=id,eq,' . $_SESSION['apiUser']['id'] : '';
            }
            return $tableName;
        } else {
            return $tableName;
        }
    },
    'authorization.tableHandler' => function ($operation, $tableName) {
        if ($_SESSION['apiUser']['id_ruolo'] != 1) {
            return ($tableName == 'utente') ? 'filter=id,eq,' . $_SESSION['apiUser']['id'] : $tableName;
        } else {
            return $tableName;
        }
    },
    'cors.allowHeaders' => 'X-Requested-With, Content-Type, Accept, Authorization, X-Authorization, X-Custom-Header, X-API-Key',
]);

The request fails because the system try to query on 'users' table that not exists.

@mevdschee
Copy link
Owner

mevdschee commented Jan 31, 2023

I think you should also set the 'dbAuth.loginTable', but I agree that is should have fallen back to 'dbAuth.usersTable'. I'll make a bugfix.

@mevdschee mevdschee added bug and removed help wanted labels Jan 31, 2023
mevdschee added a commit that referenced this issue Feb 1, 2023
@mevdschee
Copy link
Owner

Released in v2.14.18

@chattago2002
Copy link
Author

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants