benvanstaveren / Mojolicious-Plugin-Authentication

A plugin to make authentication a bit easier
http://search.cpan.org/dist/Mojolicious-Plugin-Authentication/
Other
20 stars 17 forks source link

Deep recursion at logout subroutine #20

Closed pavelsr closed 7 years ago

pavelsr commented 8 years ago

Hi all,

I have a strange problem.

When I press logout link at my project computer is hanging and I have following at morbo log:

Deep recursion on subroutine "MongoPA::Controller::Auth::logout"

This is my logout function of MongoPA::Controller::Auth module:

sub logout {
    my $self = shift;
    $self->logout;
    $self->redirect_to('/login');
  }

And this is related string from a route and template:

 $r->get('/logout')->to('auth#logout');
<a href='<%= url_for("logout") %>'>logout</a>

Is it a bug or I made something wrong?

I checked the code of logout method and I haven't found anything that can make such deep recursion error. So I'm a little bit stuck now.

benvanstaveren commented 8 years ago

Hi Pavel,

$self->logout will recurse - you have a sub 'logout' defined, and the actual 'logout' from my module is just a helper, so it'll recurse :)

If you do this, it'll work:

sub do_logout { my $self = shift; $self->logout; $self->redirect_to('/login'); }

And then refer to it with 'do_logout' in your routes :)

On 06/01/2016 04:30 PM, Pavel Serikov wrote:

Hi all,

I have a strange problem.

When I press logout link at my project computer is hanging and I have following at morbo log:

|Deep recursion on subroutine "MongoPA::Controller::Auth::logout" |

This is my logout function of MongoPA::Controller::Auth module:

sub logout { my $self = shift; $self->logout; $self->redirect_to('/login'); }

And this is related string from a route and template:

$r->get('/logout')->to('auth#logout'); logout

Is it a bug or I made something wrong?

I checked the code https://metacpan.org/source/MADCAT/Mojolicious-Plugin-Authentication-1.29/lib/Mojolicious/Plugin/Authentication.pm#L117 of logout method and I haven't found anything that can make such deep recursion error. So I'm a little bit stuck now.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/benvanstaveren/Mojolicious-Plugin-Authentication/issues/20, or mute the thread https://github.com/notifications/unsubscribe/AAQxlAIGb2bfKjHTb0KqJWzPnshYC09Nks5qHZeUgaJpZM4IrnAH.

pavelsr commented 8 years ago

Hi Ben,

Got it, thanks a lot. I just forgot that helpers and custom controller's methods have same namespace. You can close this issue.

P.S. However I think that we should figure out in documentation that to avoid recursion you shouldn't name your controller method as 'logout' :)

benvanstaveren commented 8 years ago

Yeah, that's a good point - I'm in the process of a rather significant rewrite, so I'll see if I can do something documentation/helper wise.

On 06/01/2016 04:49 PM, Pavel Serikov wrote:

Hi Ben,

Got it, thanks a lot. I just forgot that helpers and custom controller's methods have same namespace. Will close this issue.

P.S. However I think that we should figure out in documentation https://metacpan.org/pod/Mojolicious::Plugin::Authentication#logout that to avoid recursion you shouldn't name your controller method as 'logout' :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/benvanstaveren/Mojolicious-Plugin-Authentication/issues/20#issuecomment-223016842, or mute the thread https://github.com/notifications/unsubscribe/AAQxlFYfrii7MRi3MJCuWDl1mlCwcWSnks5qHZwCgaJpZM4IrnAH.