-
I need some advice: I've a controller method that is going to display details about a resource. So far, I've implemented this:
Questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Technically it is totally fine to return early from a controller. But this leads to bad user experience, since the user does not get any clues what went wrong and is just left behind on a blank screen. Better options here would be either a redirect - as you already mentioned. Or simply render a different template/text message to the client. if($not_allowed) {
$self->render(text => "access not allowed", status => 403);
return;
} For more sophisticated authentication logic you may even utilize the |
Beta Was this translation helpful? Give feedback.
-
Yes, I know, but I have to run the code either with authenticated or not-authenticated uses, so I prefer to check the authentication in the controller method (in the above example I was quitting if not authenticated, but then I will add another path for unauthenticated users).
Please warn if the above is wrong. |
Beta Was this translation helpful? Give feedback.
Technically it is totally fine to return early from a controller. But this leads to bad user experience, since the user does not get any clues what went wrong and is just left behind on a blank screen.
Better options here would be either a redirect - as you already mentioned. Or simply render a different template/text message to the client.
For more sophisticated authentication logic you may even utilize the
under
method of Mojolicious. This way you may even prevent execution of your controller action completely, since the wrapping code inunder
already handles unauthenticated users.