janko / rodauth-rails

Rails integration for Rodauth authentication framework
https://github.com/jeremyevans/rodauth
MIT License
571 stars 40 forks source link

Simple install doesn't work : undefined method `login_path' #84

Closed bdavidxyz closed 2 years ago

bdavidxyz commented 2 years ago

Sorry to open the 43rd issue, 42 was perfect ;)

Step to reproduce. MacOS 10.15.7 :

$> ruby -v  
ruby 3.0.0p0  
$> bundle -v  
Bundler version 2.2.11  
$> npm -v  
8.3.0 
$> yarn -v  
1.22.10
$> psql --version  
psql (PostgreSQL) 13.1 

Rails 7 will be used

  mkdir rodemo && cd rodemo  
  echo "source 'https://rubygems.org'" > Gemfile  
  echo "gem 'rails', '7.0.0'" >> Gemfile  
  bundle install  
  bundle exec rails new . --force -d=postgresql  
  bundle update

  # Create a default controller
  echo "class HomeController < ApplicationController" > app/controllers/home_controller.rb
  echo "end" >> app/controllers/home_controller.rb

  # Create routes
  echo "Rails.application.routes.draw do" > config/routes.rb
  echo '  get "home/index"' >> config/routes.rb
  echo '  root to: "home#index"' >> config/routes.rb
  echo 'end' >> config/routes.rb

  # Create a default view
  mkdir app/views/home
  echo '<h1>This is home</h1>' > app/views/home/index.html.erb

  # Create database and schema.rb
  bin/rails db:create
  bin/rails db:migrate

Now let's add rodauth-rails to this simple, default Rails app :

inside Gemfile

gem "rodauth-rails"

then bundle install

then bin/rails generate rodauth:install

then bin/rails db:migrate

then bin/rails rodauth:routes --trace

Will produce this error :

Invoke rodauth:routes (first_time) Invoke environment (first_time) Execute environment Execute rodauth:routes Routes handled by RodauthApp: rails aborted! NoMethodError: undefined method login_path' for #<Class:0x00007f8e7f08d850> /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rodauth-rails-0.18.1/lib/rodauth/rails/tasks.rake:14:inpublic_send' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rodauth-rails-0.18.1/lib/rodauth/rails/tasks.rake:14:in block (4 levels) in <main>' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rodauth-rails-0.18.1/lib/rodauth/rails/tasks.rake:10:inmap' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rodauth-rails-0.18.1/lib/rodauth/rails/tasks.rake:10:in block (3 levels) in <main>' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rodauth-rails-0.18.1/lib/rodauth/rails/tasks.rake:7:ineach' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rodauth-rails-0.18.1/lib/rodauth/rails/tasks.rake:7:in block (2 levels) in <main>' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:281:inblock in execute' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:281:in each' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:281:inexecute' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:219:in block in invoke_with_call_chain' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:199:insynchronize' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:199:in invoke_with_call_chain' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/task.rb:188:ininvoke' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:160:in invoke_task' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:116:inblock (2 levels) in top_level' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:116:in each' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:116:inblock in top_level' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:125:in run_with_threads' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:110:intop_level' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/commands/rake/rake_command.rb:24:in block (2 levels) in perform' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/application.rb:186:instandard_exception_handling' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/commands/rake/rake_command.rb:24:in block in perform' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:inwith_application' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/commands/rake/rake_command.rb:18:in perform' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/command.rb:51:ininvoke' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/railties-7.0.0/lib/rails/commands.rb:18:in <main>' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:inrequire' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in block in require_with_bootsnap_lfi' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/loaded_features_index.rb:100:inregister' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in require_with_bootsnap_lfi' /Users/david/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bootsnap-1.9.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:inrequire' bin/rails:4:in `

' Tasks: TOP => rodauth:routes

janko commented 2 years ago

Yes, the rodauth:routes rake task in latest rodauth-rails version is incompatible with the latest Rodauth version. This has been fixed in master, please use that for the time being.

I'm close to releasing rodauth-rails 1.0, the main blocker is currently that I've been randomly receiving ActionController::InvalidAuthenticityToken errors when testing with Rails 7 & Hotwire, so I would like to get to the bottom of it first.

janko commented 2 years ago

Alternatively, you can enable the path_class_methods feature in your Rodauth config.

janko commented 2 years ago

Version 1.0 has been released, which fixes this issue.