generator-for-devise-jwt: Implement the generator for devise-jwt#5
generator-for-devise-jwt: Implement the generator for devise-jwt#5TheZero0-ctrl wants to merge 1 commit intomainfrom
Conversation
|
|
||
| private | ||
|
|
||
| def devise_jwt_secret_key |
There was a problem hiding this comment.
Let's make sure to let user know where we have configured these keys in the after installation message so they can change this if required and configure the key correctly.
You can take a look at rswag PR for the example.
|
@TheZero0-ctrl I hope you also created a new Rails project, tried all configuration options here and made sure this generator is working without issue for each of them as well. |
I have tested and everything works if devise is correctly configure for the api |
|
|
||
| inject_into_file "config/initializers/devise.rb", | ||
| optimize_indentation(jwt_config, 2), | ||
| before: /^end/ |
There was a problem hiding this comment.
Will this regex work if there are multiple do .. end block inside the file beforehand? We might want to update this to match the last end most probably by looking at the "end + blank lines (could be multiple sometimes, can't predict) + end of file (\Z)"
|
|
||
| def add_devise_jwt_config_to_devise_initializer | ||
| say "Adding devise-jwt configurations to a file `config/initializers/devise.rb`", :green | ||
| say "Value for jwt.secret will be used from `#{devise_jwt_secret_key}`. You can change this values if they don't match with your app.\n", :yellow |
There was a problem hiding this comment.
Let's update to:
say "❗️❗️\nValue for jwt.secret will be used from `#{devise_jwt_secret_key}`. You can change this values if they don't match with your app.\n", :yellow
Also let's move this line after "inject_into_file" i.e. after actual configuration has been added
| add_index :users, :jti, unique: true | ||
| RUBY | ||
|
|
||
| inject_into_file Dir["db/migrate/*_add_jti_to_#{model_name.pluralize}.rb"][0], |
There was a problem hiding this comment.
Any reason why we need to use Dir[..] ?
Just "db/migrate/*add_jti_to#{model_name.pluralize}.rb" should also work here.
There was a problem hiding this comment.
it require actual file name so *add_jti_to#{model_name.pluralize}.rb don't work
There was a problem hiding this comment.
That's strange, that should have worked: https://github.com/rails/thor/blob/main/lib/thor/actions/inject_into_file.rb
What type of error was it throwing when Dir is not used?
There was a problem hiding this comment.
as it take string not regex * will evaluate as literal *
so, error it throw is No such file or directory "*_add_jti_to#{model_name.pluralize}.rb"
| def configure_denylist_strategy | ||
| Bundler.with_unbundled_env do | ||
| run "bundle exec rails generate model jwt_denylist --skip-migration" | ||
| run "bundle exec rails generate migration create_jwt_denylist" |
There was a problem hiding this comment.
Let's use "generate", let's fix this throughout the file.
24f10ca to
776e246
Compare
776e246 to
5fd962b
Compare
5fd962b to
e474e3f
Compare
e474e3f to
fc6f26c
Compare
fc6f26c to
54b8d5e
Compare
Task Done
I have run into following problem
bundle exec rails...bundle exec rails..are failing