simov / express-admin

MySQL, MariaDB, PostgreSQL, SQLite admin for Node.js
MIT License
1.18k stars 223 forks source link

Exception right after login #80

Open ghost opened 9 years ago

ghost commented 9 years ago

So I was giving this project a try but as soon as I click that "Login" button it throws an exception. It only does it, when the user and password match with what's in users.json. It does not crash when it was not able to login but shows the login page again as expected.

TypeError: Cannot read property 'length' of undefined
   at Object.select (<PATH>\node_modules\express-admin\lib\qb\lst.js:42:27)
   at _data (<PATH>\node_modules\express-admin\routes\listview.js:38:9)
   at Object.exports.get [as handle] (<PATH>\node_modules\express-admin\routes\listview.js:26:2)
   at next_layer (<PATH>\node_modules\express-admin\node_modules\express\lib\router\route.js:103:13)
   at Object.exports.restrict [as handle] (<PATH>\node_modules\express-admin\routes\auth.js:20:31)
   at next_layer (<PATH>\node_modules\express-admin\node_modules\express\lib\router\route.js:103:13)
   at Route.dispatch (<PATH>\node_modules\express-admin\node_modules\express\lib\router\route.js:107:5)
   at <PATH>\node_modules\express-admin\node_modules\express\lib\router\index.js:213:24
   at Function.proto.process_params (<PATH>\node_modules\express-admin\node_modules\express\lib\router\index.js:286:12)
   at next (<PATH>\node_modules\express-admin\node_modules\express\lib\router\index.js:207:19)

Anyone experienced the same problem?

simov commented 9 years ago

Which version of Express Admin you are using? I don't see such expression in \lib\qb\lst.js on line 42

ghost commented 9 years ago

Version 1.2.6 Sorry. It's on line 43 in the repository. I was already trying to fix it on my own and missed out putting a blank line in again.

simov commented 9 years ago

Check your settings.json file, it should be generated and filled with defaults on first start. Your configuration is corrupted for some reason. I can't tell exactly what it is just by looking at this error message.

ghost commented 9 years ago

it seems I get empty req.params in getArgs (listview.js, line 16) which results in more undefineds along the way.

simov commented 9 years ago

Which version of node do you use? How is your url looking in the browser's address bar, I can't imagine req.params being empty.

ghost commented 9 years ago

Node is version 0.12.0 The URL looks like this http://192.168.0.2:8080/backend I'm running express-admin in embedded mode.

args = {dpath: "<PATH>",
        config: {sqlite: {database: "<PATH>/store.db"}
                 app: {upload: "<PATH>/uploads"},
                       root: "/backend",
                       layouts: true,
                       themes: true,
                       languages: true},
      settings: require("<PATH>/settings.json"),
      custom: {},
      users { ... }
};
......
app.use("/backend", admin);
simov commented 9 years ago

Yeah but in order to get the error in the listview route you have to navigate to something like http://192.168.0.2:8080/backend/[slug] And after login the admin redirects to the mainview, not the listview.

simov commented 9 years ago

@yhmtg my system tests just hanged on the login screen when using sqlite in node 0.12.

It seems that there is a breaking change in 0.12 that affects the admin, I'll take a look at it this weekend.

simov commented 9 years ago

@yhmtg it turned out that I needed to re-build my sqlite3 module for node 0.12

Here is what I did

$ nvm use 12 # you use `nvm` right?
$ npm install -g express-admin sqlite3@3.0.5
$ admin /path/to/config

So as far as I'm concerned the admin is working with sqlite and node 0.12

ghost commented 9 years ago

Didn't work for me sadly. Still the same error.

simov commented 9 years ago

If you can create a small test case that reproduces the bug it will be great. Like a small db with only one table + the config you are using.

bnny commented 9 years ago

I ran into the same problem. I am using an sqlite db without explicitly specified primary keys. Adding "pk": "rowid" to every table in settings.json fixed it for me.

simov commented 9 years ago

Thanks for the feedback @bnny ! express-admin requires you to have primary keys in your tables. I'm adding rowid to my sqlite tables as well.

jb92130 commented 7 years ago

Hello,

Same for me like bnny, I'd to add the pk. The generator doesn't detect the pk. Same for the kind of field. If it's date, I'd to change manually in the config for the controller.

Kind regards.

JB.