jeremyevans / rodauth

Ruby's Most Advanced Authentication Framework
http://rodauth.jeremyevans.net
MIT License
1.65k stars 95 forks source link

Two Factor authentication issue: "undefined method `[]' for nil:NilClass" #389

Closed jgthms closed 6 months ago

jgthms commented 6 months ago

Hi and thanks for creating this library.

I am developing an app with both a main account type, and an admin one. I've succesfully followed these instructions to create both account types.

After finalising all the website features, I decided to reset the database with rake db:reset to see how the app would behave on a fresh install.

After creating a new admin account, I'm running into this error: image

My rodauth_admin.rb configuration looks like this: image

Did I miss a step somewhere?

jgthms commented 6 months ago

My rodauth_app.rb configuration is:

class RodauthApp < Rodauth::Rails::App
  # primary configuration
  configure RodauthMain

  # secondary configuration
  configure RodauthAdmin, :admin

  route do |r|
    rodauth.load_memory # autologin remembered users

    r.rodauth # route rodauth requests

    # ==> Authenticating requests
    # Call `rodauth.require_account` for requests that you want to
    # require authentication for. For example:
    #
    # # authenticate /dashboard/* and /account/* requests
    # if r.path.start_with?("/dashboard") || r.path.start_with?("/account")
    #   rodauth.require_account
    # end

    # ==> Secondary configurations
    r.rodauth(:admin) # route admin rodauth requests

    if request.path.start_with?("/admin")
      rodauth(:admin).require_account
    end

    # require MFA if the user is logged in and has MFA setup
    if rodauth(:admin).uses_two_factor_authentication?
      rodauth(:admin).require_two_factor_authenticated
    end
  end
end
jeremyevans commented 6 months ago

You appear to be using rodauth-rails, so please open a discussion in the rodauth-rails repository: https://github.com/janko/rodauth-rails/discussions/new/choose

Only post an issue here if you can reproduce the bug in Rodauth itself (without rodauth-rails).

jgthms commented 6 months ago

Sorry! Wrong repo indeed.