nsarno / knock

Seamless JWT authentication for Rails API
MIT License
2.07k stars 253 forks source link

adding error when key is missing #260

Closed renatamarques97 closed 4 years ago

renatamarques97 commented 4 years ago

resolves #212

@andrerpbts let me know how to deal with multiple rails versions

andrerpbts commented 4 years ago

I think we don't need to deal with multiple rails versions because it's only the fallback that we automaticaly set and Knock users can change it in the config/knock.rb file into their own applications. Then, I think the solution provided here, won't work if an user sets an empty string in that file... Can you confirm it, please?

My suggestion is to transform the mattr_accessor into mattr_writer + a class getter method, that will handle empty strings to raise that error. I would leave it raise NoMethodError in older versions were Rails.application.secrets doesn't exist, and user can fix that changing for the more appropriated value...

Also, I suggest to create a specific error class for that empty string exception as well...

Last, please, add some test to that 👍

renatamarques97 commented 4 years ago

Thanks for clarifying me