Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generator-for-devise-jwt: Implement the generator for devise-jwt #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TheZero0-ctrl
Copy link
Collaborator

@TheZero0-ctrl TheZero0-ctrl commented Mar 18, 2024

Task Done

  • Added generators for devise-jwt

I have run into following problem

  • I am not able to run bin/setup due to the version mismatch between ruby 2.7.3 and sqlite3
  • So I did bin/setup by using higher version of ruby but then all test are failing
  • So first I use higher version ruby then after running bin/setup and I use ruby 2.7.3, now tests are passing expect the test which have to use command bundle exec rails...
  • error was version mismatch between rake and ruby 2.7.3 but if I add appropriate rake version then it will show error for other gems
  • So conclusion is in this PR test needed to run bundle exec rails..are failing


private

def devise_jwt_secret_key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@coolprobn
Copy link
Member

@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.

@TheZero0-ctrl
Copy link
Collaborator Author

@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/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why we need to use Dir[..] ?

Just "db/migrate/*add_jti_to#{model_name.pluralize}.rb" should also work here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it require actual file name so *add_jti_to#{model_name.pluralize}.rb don't work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Collaborator Author

@TheZero0-ctrl TheZero0-ctrl Mar 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use "generate", let's fix this throughout the file.

@TheZero0-ctrl TheZero0-ctrl force-pushed the generator-for-devise-jwt branch from 776e246 to 5fd962b Compare May 21, 2024 10:39
@TheZero0-ctrl TheZero0-ctrl force-pushed the generator-for-devise-jwt branch from 5fd962b to e474e3f Compare June 6, 2024 04:36
@coolprobn coolprobn added the PR CREATED PR has been created in main Boring Generators Github label Jun 17, 2024
@TheZero0-ctrl TheZero0-ctrl force-pushed the generator-for-devise-jwt branch from e474e3f to fc6f26c Compare June 26, 2024 16:13
@TheZero0-ctrl TheZero0-ctrl force-pushed the generator-for-devise-jwt branch from fc6f26c to 54b8d5e Compare June 30, 2024 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR CREATED PR has been created in main Boring Generators Github
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants