janko / rodauth-rails

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

Sequel DB Error with secondary model #183

Closed jamier-92 closed 1 year ago

jamier-92 commented 1 year ago

Hello, Firstly, this gem is amazing and thank you for all the work you've put in.

I've set up an initial model with JWT-Refresh in api mode and it all works fine :)

I'm now trying to create a secondary admin model and thought it was all configured correctly but when sending a POST to admin/login i get an error because it's looking for accounts and not admins at /admin/login

Sequel (0.3ms) SELECT * FROM "accounts" WHERE (("email" = '[email]') AND ("status" IN (1, 2))) LIMIT 1

How do I make the SQL query target admins instead of accounts?

Thank you

class ApplicationController < ActionController::API
    after_action :set_jwt_token

    def current_account
        rodauth.rails_account
    end
    #helper_method :current_account

    private

    def set_jwt_token
        if rodauth.use_jwt? && rodauth.valid_jwt?
            response.headers["Authorization"] = rodauth.session_jwt
        end
    end

    def authenticate
            rodauth.require_account # redirect to login page if not authenticated
    end

end
class RodauthApp < Rodauth::Rails::App
  configure RodauthMain
  configure RodauthAdmin, :admin

  route do |r|
    r.rodauth 
    r.rodauth(:admin) 
  end
end
class RodauthAdmin < Rodauth::Rails::Auth
...
    rails_controller { Admin::RodauthController }
jamier-92 commented 1 year ago

I found the error I had to include

accounts_table :admins

in rodauth_admin.rb