Skip to content

Need some advice on the correct way to "stop" a rendering (?) #2162

Closed Answered by ghandmann
fluca1978 asked this question in Q&A
Discussion options

You must be logged in to vote

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 under method of Mojolicious. This way you may even prevent execution of your controller action completely, since the wrapping code in under already handles unauthenticated users.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by fluca1978
Comment options

You must be logged in to vote
1 reply
@ghandmann
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants