Closed caseyprovost closed 4 years ago
Hmm... this is an interesting case. The reason this is happening is because the inertia front-end interprets every non 2xx
status as an error, but doesn't have a special case for 401
.
I assume this is happening automatically because of devise? Is it possible to have devise send down the inertia headers ('x-inertia' => true
)? If we can do that, inertia's frontend will interpret this like any other inertia response.
If not, we'll have to look into adding a special case for 401
which would be in the https://github.com/inertiajs/inertia repo somewhere around here: https://github.com/inertiajs/inertia/blob/70b6bda4f23061558d48f91a95baaa9062b9e0bb/src/inertia.js#L80
I encountered a similar problem while creating the PingCRM demo application. Here is my solution:
Thanks @ledermann! My next test is to see what happens when the app raises a Pundit::AccessDeniedError.
@caseyprovost: Here are some more suggestions for exception handling:
Handling AccessDenied exceptions: https://github.com/ledermann/pingcrm/blob/c53d3b40264069bb6dadf63f38b37284f6bd7499/app/controllers/concerns/auth.rb#L9-L13
Handling exceptions in general: https://github.com/ledermann/pingcrm/blob/a0c6dc89d39768397dfe713379d846665051e323/config/application.rb#L34-L41
The idea is to catch the exception and render this Vue component instead: https://github.com/ledermann/pingcrm/blob/master/app/javascript/Pages/Error.vue
Thanks again mate! I’ll definitely be using this 😎👍
@BrandonShar I'm closing this as @ledermann did a great job showing how to make it work :) Might be nice to put some of this in a wiki though or in the Readme :)
Using the latest Rails and devise I get the following screen when trying to sign in as an unconfirmed user.
What I expected to happen is to be redirected back to the sign in page and have that message shown there in a flash message. Or at least be able to customize the controller to do so.