-
Notifications
You must be signed in to change notification settings - Fork 178
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
Using Trestle 0.10.0 - unable to use Stimulus controller #486
Comments
Right now, trestle-auth doesn't include any JavaScript by default on the login page, which for this case in particular means the Stimulus initialization code is not being ran. See the auth layout for what it does include. At some point in the future I'd like to add better support for a multi-step 2FA (or oAuth) login flow, which might mean I split up the JavaScript into 'core' and 'main' chunks, where 'core' includes the Stimulus / Turbo setup and other basics. As a workaround for now you can inject your custom JavaScript using the import { Application } from '@hotwired/stimulus'
window.Stimulus = Application.start()
// Manual registration or use:
// import { definitionsFromContext } from '@hotwired/stimulus-webpack-helpers'
import AuthController from "./auth"
Stimulus.register("auth", AuthController) |
When I added loading of this js to trestle.rb hook, I got:
Also as I mentioned, that controller didn't connect even when added data-controller='auth' to one of users_admin.rb fields. Like Trestle wouldn't see that controller. Do I need to register it with something like that: Now I am thinking on using devise build in views for user login related stuff, but when I uninstall trestle-auth, how hard will it be to require logging in before user is redirected to admin pages? Or would you recommend sticking with trestle-auth and adding new views and controllers? Thanks! |
This sounds like you might need to have the script run through JS precompilation. I'm working on some docs to cover custom assets with the main JS asset bundling solutions, but if you let me know which one you are using (e.g. jsbundling-rails with esbuild), I can give you some specific examples.
Yes, you will need to register manually with
I'd definitely recommend using trestle-auth with the Devise integration, though in your situation you may want to disable Trestle's login/logout routes and use Devise's, by setting |
@spohlenz Thanks for the tip with using both trestle-auth and Devise login pages! Works like a charm!
I am using Importmap for Rails |
Trestle unfortunately doesn't yet support importmaps. There are a couple of open PRs in importmap-rails for dealing with multiple entry points (i.e. your app vs Trestle admin) so I'll need to see how they shake out before I can add support. You may find success by, instead of importing For the login page, you can try adding |
Hi!
I am working on adding "Reset password" to trestle-auth provided login page. During that I have discovered that my simple controller is not being connected.
First I wanted to add this:
The
auth_controller.js
:Then I tried to see if I am able to load this controller at all in Trestle, so I tried adding this in one of the admin files:
Still nothing. I was able to see data-controller="auth" in the source page for given elements, but connect was not ran.
Then I added the same controller to a main page(that is not using Trestle) and the controller connected.
Do I need to add some special configuration?
Thanks!
The text was updated successfully, but these errors were encountered: