express-admin icon indicating copy to clipboard operation
express-admin copied to clipboard

Exception right after login

Open ghost opened this issue 10 years ago • 14 comments

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?

ghost avatar Feb 26 '15 12:02 ghost

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

simov avatar Feb 26 '15 13:02 simov

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.

ghost avatar Feb 26 '15 13:02 ghost

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.

simov avatar Feb 26 '15 13:02 simov

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

ghost avatar Feb 26 '15 13:02 ghost

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.

simov avatar Feb 26 '15 14:02 simov

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);

ghost avatar Feb 26 '15 14:02 ghost

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 avatar Feb 26 '15 14:02 simov

@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 avatar Feb 26 '15 14:02 simov

@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 [email protected]
$ admin /path/to/config

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

simov avatar Mar 01 '15 10:03 simov

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

ghost avatar Mar 02 '15 19:03 ghost

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.

simov avatar Mar 02 '15 21:03 simov

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.

bnny avatar May 12 '15 11:05 bnny

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.

simov avatar May 13 '15 11:05 simov

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.

jb92130 avatar Aug 01 '17 08:08 jb92130