-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Rails 7 devise flash messages not being shown #5446
Comments
Update, I found an error reported in the browser console, i don't know if this is useful
A failure in the clubs controller generates a flash error message and a different message in the console The devise part generates the 'must redirect' message in the console like this screenshot |
I am also having this issue. I thought that this might fix it but it doesn't... ref: #5439 Quick fix, tl;drAdd config.navigational_formats = ['*/*', :html, :turbo_stream] There's also this open PR that may be of use: #5440 |
Thanks, it's nice to know it's not just me having trouble :-) |
Did it work for you, I just tried it, it's not working for me. Note: after 2 hours i found this episode of gorails, it's solved |
@bouaik Nice one! Thank you for sharing that. Bit of a fiddly one, but it's mostly working for me. Other than a failed log in attempt (logs below) - this just returns to the log in page without any error message. Have you got this working too? logs:
No flash message being set... |
@AlanDonohoe , yes it's working for me, setting :turbo_stream as a navigational format solves the 401, but not the flash messages, you have to add the same code as in the video to make it all working. |
And full code here hotwired/turbo#45 from the very clever @excid3 - thank you so much! 👏 |
I am an absolute beginner, so pardon me for any mistake. But I have been facing a similar issue to this, where I cannot sign up a user. The sqlite3 database remains empty even after pressing sign up. The browser console shows the following error: While terminal serves me a rollback transaction:
I tried pasting the following in Demo Github Repo : https://github.com/jaindivij21/friends-list |
maybe it can help you. |
A temporary solution/hack would be to set:
|
+1 Surprised Rails 7 isn't working out of the box with Devise yet 🤔 |
Hi guys, that's works for me! |
@awais-amjed You are right. I don't know why it works after I removed it. Thanks a lot |
@awais-amjed Thanks, that worked for me as well |
Can you actually comment that out without breaking all of the hotwire stuff like turbo and stimulus? |
@amo13 No, actually that's not a good way to do this. We should use above solutions SO GUYS DON'T REMOVE THAT LINE IF YOU NEED HOTWIRE. |
Is this fixed now, I don't really want to be putting in hacks to get things working ? |
I think the issue is about setting the right response status when devise renders
Will not show message
Any suggestions on how we can achieve a similar result with devise? |
I tried both approaches and they worked just fine. Finally decided to override 📎 I created a gist with all the information may come in handy for this issue. |
Is this issue still relevant? What is the current status of this problem? |
This issue is still unresolved. Use this working hack for now:
This simply disables Turbo for this form submission (but not anywhere else). |
Devise had issues with Turbo and did'nt work out of the box: heartcombo/devise#5446 Workaround/solution as shown here: https://betterprogramming.pub/devise-auth-setup-in-rails-7-44240aaed4be
* refactor: Migrated to importmap instead of webpacker Importmap (https://github.com/rails/importmap-rails) instead of the retired webpacker * Added bootstrap in proper importmap manner * refactor: Removed webpacker gem Removal of gem introduced a couple a breaking issues that were also addressed in this commit: - Turbolinks needed to replaced by turbo - Route to delete needed to follow a new format * fix: Fixed devise config to work with Turbo Devise had issues with Turbo and did'nt work out of the box: heartcombo/devise#5446 Workaround/solution as shown here: https://betterprogramming.pub/devise-auth-setup-in-rails-7-44240aaed4be * fix: Fixed delete format for Program * Undid changes required for windows local running * Removed yarn and webpacker steps from Github tests * Removed webpacker + yarn steps in makefile * Removed yarn and package.json from Dockerfile * fix: Fix to destroy tests failing The addition of the 'Turbo' library changed the way delete alert was shown. For some reason, test was too fast and click action does not work. Adding a 1 second delay before click fixed the test.
This is the correct answer. |
Thank you so much! This saved me. |
<%= bootstrap_form_with model: @Company, data: { turbo: false } do |form| %> |
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
…adern.auth do' to verify password and call sign_method, redirectin to root path with notice in the correct local of front end to correct the issue heartcombo/devise#5446 in this project
The main branch should contain all that's necessary for fully working with Turbo now, which should fix this. A new version will be released soon, but feel free to test it out from the main branch in the meantime, and report back on any issues. Thanks. |
Thank you for fixing and sharing, and my apologies to all here that since I discovered this and created the issue a year ago I've had zero time to code and respond (I code for fun alone and this year was too busy for me, that time will come again and I appreciate all of your help). |
@awais-amjed thank, I remove <%= javascript_importmap_tags %> and it work for me. |
Just as @carlosantoniodasilva mentioned - this is now included in the latest. I used the following gems (although I don't think I needed to)
Make sure there's a flash message included in your template (application.erb or devise.erb) to display the error messages - flash.each do |name, msg|
.message[class=flash_class(name.to_sym)]
= content_tag :div, msg, id: "flash_#{name}" |
The latest stable version v4.9.2 should have all you need to, in case you don't want to bundle from main directly. |
I ended up here from https://www.youtube.com/watch?v=m3uhldUGVes&t |
Environment
Current behavior
A new rails 7 app with devise.
Flash messages from Devise are not shown but Flash messages generated from another controller are shown.
The Devise flash messages appear to be being generated in the console rendering messages when a new user is registered with a password that is too short
Example minimal app:
https://github.com/steveroot/rails7deviseflash
(Add a 'new club' to see working flash message, Register a new user with a short password to not see flash message yet see render message in console)
Expected behavior
Flash messages shown on screen when generated
The text was updated successfully, but these errors were encountered: