preaction / Yancy

The Best Web Framework Deserves the Best Content Management System
http://preaction.me/yancy/
Other
54 stars 21 forks source link

Can't Use read_schema => 0 with Auth::Password #69

Closed ViktorNacht closed 5 years ago

ViktorNacht commented 5 years ago

It might be more honest to say I can't seem to them together. I'm attempting to migrate from Auth::Basic to Auth:Password (you can see my old config in the comment), and I keep getting an error message. I can't / don't want to use read_schema => 1 because it pukes on all of my mysql JSON columns.

My configuration:

plugin Yancy => {
  backend => app->config->{dsn},
  read_schema => 0,
  schema => {
    admins => {
      'x-id-field' => 'username',
      properties => {
        username => { type => 'string' },
        password => { type => 'string' },
      },
    },
  }
};

# app->yancy->plugin('Auth::Basic' => {
#   collection => 'admins',
#   password_digest => { type => 'SHA-512' },
# });

app->yancy->plugin('Auth::Password' => {
  schema => 'admins',
  username_field => 'username',
  password_field => 'password',
  password_digest => {
    type => 'SHA-512',
  },
});

My error message:

Can't load application from file "/home/www/sites/[...]/app/puravida.pl": Can't use an undefined value as an ARRAY reference at /opt/perl5/perls/puravida/lib/site_perl/5.24.3/Yancy/Plugin/Auth/Password.pm line 314.

Is it bug or do I need to make changes to the core Yancy config?

preaction commented 5 years ago

This was definitely a bug: Looks like since there are no "required" fields in your schema, the code accidentally put an undef where it was expecting an arrayref. I've fixed it and will make a release today. Thanks for reporting this!

ViktorNacht commented 5 years ago

Wow, thank you for the quick fix! I probably found this because I'm using the backend authentication without the frontend manager.

preaction commented 5 years ago

Nah, this would've happened for any schema that didn't have any required fields (which, you're right, read_schema => 1 would have found the primary key at least and marked it as required). Slight oversight on my part :)