Skip to content

Commit

Permalink
Added installation rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
kobaltz committed Aug 20, 2024
1 parent 9767eda commit 98b7c5d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,23 @@ add_foreign_key :nfcs, :users, column: :user_id unless foreign_key_exists?(:nfcs
```

## Installation

### Automatic Installation

Add this line to your application's Gemfile:

```ruby
bundle add action_auth
```

Then run the rake task to copy over the migrations, config and routes.

```bash
bin/rails action_auth:install
```

### Manual Installation

Add this line to your application's Gemfile:

```ruby
Expand Down
53 changes: 49 additions & 4 deletions lib/tasks/action_auth_tasks.rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
# desc "Explaining what the task does"
# task :action_auth do
# # Task goes here
# end
desc "Installs Configs, Migrations, and Routes for ActionAuth"
namespace :action_auth do
task :install do
# Copies to config/initializers/action_auth.rb
puts "Installing ActionAuth Configs"
config_file_path = Rails.root.join('config', 'initializers', 'action_auth.rb')
unless File.exist?(config_file_path)
File.open(config_file_path, 'w') do |file|
file.puts <<~RUBY
# ActionAuth.configure do |config|
# config.allow_user_deletion = true
# config.default_from_email = "from@example.com"
# config.magic_link_enabled = true
# config.passkey_only = true # Allows sign in with only a passkey
# config.pwned_enabled = true # defined?(Pwned)
# config.verify_email_on_sign_in = true
# config.webauthn_enabled = true # defined?(WebAuthn)
# config.webauthn_origin = "http://localhost:3000" # or "https://example.com"
# config.webauthn_rp_name = Rails.application.class.to_s.deconstantize
# end
RUBY
end
puts "Created config/initializers/action_auth.rb"
else
puts "Config file already exists at config/initializers/action_auth.rb"
end

# Installs the ActionAuth Migrations
puts "Installing ActionAuth Migrations"
Rake::Task["action_auth:install:migrations"].invoke

# Add ActionAuth routes to config/routes.rb
puts "Installing ActionAuth Routes"
routes_file_path = Rails.root.join('config', 'routes.rb')
route_line = "mount ActionAuth::Engine => \"/action_auth\""
routes_content = File.read(routes_file_path)
unless routes_content.include?(route_line)
insert_after = "Rails.application.routes.draw do"
new_routes_content = routes_content.sub(/(#{insert_after})/i, "\\1\n #{route_line}\n")
File.open(routes_file_path, 'w') do |file|
file.puts new_routes_content
end
puts "Added ActionAuth route to config/routes.rb"
else
puts "ActionAuth route already present in config/routes.rb"
end

end
end

0 comments on commit 98b7c5d

Please sign in to comment.