-
-
Notifications
You must be signed in to change notification settings - Fork 256
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
Integrating Rails 8 authentication with Avo #3361
Comments
I'm having a look into this one. Rails.configuration.to_prepare do
Avo::ApplicationController.include Authentication
end |
@matiaskorhonen @adrianthedev I was just hacking on a new Rails 8 app tonight and decided to give it a shot...MAN, what a pain. The initial solution from Adrian worked great, but everything blew up as soon as I added Pundit for authorization. I spent hours trying to figure out why my policy scopes were receiving Turns out that the That's probably a safe change for the new Rails 8 auth template anyways, as you probably want to authenticate a user before attempting to do anything else in most cases. |
Yeah, we need to do more work on the default Rails authorization generator. I started that and it's not straightforward once you see that there is no real indicator that the user is using the Rails generator. I'll hack more on this so we have it properly supported by the next Avo release. ... And hopefully not broken by the next Rails release 😅 |
@adrianthedev - yeah, since it's essentially a template to roll your own auth, it makes sense that there's no way to detect the config from the Avo side. Seems like the simplest thing to do for now, might be to have some sort of flag for "use rails auth" that would include the Authentication module before any other modules in the base Avo controller. From there, an Avo user should be able to use the existing Happy to hack on it with you at some point 😄 |
I haven't tested this out but perhaps one choice would be to have some sort of more generic way of including modules in the Avo base controller. Since it feels like there are difficulties when using any authentication besides just Devise… Maybe something like: Avo.configure do |config|
config.controller_includes = [Authentication]
# config.current_user_method = …
# and so forth
end |
We thought about that solution @matiaskorhonen, but the fact of the matter is that we'll build a mechanism to take that config, store it, and then dynamically include it, when, in reality, if you just use the config.controller_includes = [Authentication]
# versus
Rails.configuration.to_prepare do
Avo::ApplicationController.include Authentication
end And in the end it doesn't solve the problem with the order of the actions. |
Hey @davidlormor. I can't replicate that behavior.
What should be broken? I can navigate Avo and all the policy methods are applied. |
@adrianthedev hmmm...sounds like the same general order of operations I used to set things up. I've had to yank out our Avo authorization for now (realized I had access to Avo pro/advanced through my other company's key, but I had to remove that... 😉). From what I remember, Avo was trying to run the authorization check before Anyways, happy to continue looking into this, but I'd need some help with a license for local testing... |
@adrianthedev just took a look at the PRs you tagged, from what I remember the issue seemed to be coming from the |
Describe the bug
I'm trying to figure out how to integration Rails 8's new built-in/generated authentication with Avo and it's a bit of a struggle.
Steps to Reproduce
Steps to reproduce the behavior:
rails new avo-rails-8-auth
)bin/rails app:template LOCATION='https://avohq.io/app-template'
)bin/rails generate authentication && rails db:migrate
)app/controllers/concerns/authentication.rb
)Expected behavior & Actual behavior
Configuring the authentication in Avo is unintuitive. Maybe the Avo application controller needs to be monkey patched to include the Authentication concern? I tried doing that but couldn't get it to actually work…
Models and resource files
Reproduction repo at: https://github.com/matiaskorhonen/avo-rails-8-auth
System configuration
Avo version: 3.13.7
Rails version: 8.0.0.rc1
Ruby version: 3.3.5
License type:
Are you using Avo monkey patches, overriding views or view components?
Screenshots or screen recordings
—
Additional context
—
Impact
(High impact but on a project that doesn't matter)
Urgency
The text was updated successfully, but these errors were encountered: