Skip to content
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

How to make logout (yancy->auth->clear) #91

Closed
pavelsr opened this issue Apr 6, 2020 · 1 comment
Closed

How to make logout (yancy->auth->clear) #91

pavelsr opened this issue Apr 6, 2020 · 1 comment

Comments

@pavelsr
Copy link

pavelsr commented Apr 6, 2020

Since nowhere in docs mention what is reserved session key for storing current user (I assume it's always session->{yancy}{auth} but still ) I think it could be useful to add into Yancy::Plugin::Auth section how to properly logout. I assume that it's always possible to do with delete $c->session->{yancy}{auth}, something like

get '/logout' => sub {
  my ( $c ) = @_;
  delete $c->session->{yancy}{auth};
  $c->redirect_to('/');
};

But maybe there is some public method to do logout ? Or should we add it?

Searching by code I've found that you made logout in Yancy::Plugin::Auth::Basic like

sub _get_logout {
    my ( $c ) = @_;
    $c->yancy->auth->clear;
    $c->flash( info => 'Logged out' );
    return $c->render( 'yancy/auth/basic/login' );
}

But when I tried to do similar in my app

get '/logout' => sub {
  my ( $c ) = @_;
  $c->yancy->auth->clear;  # or app->yancy->auth->clear
  $c->redirect_to('/');
};

I've got an error, Can't locate object method "clear" via package "Mojolicious::Renderer::Helpers::4d3bfb8b02efde8b1bbef4956167936a"

@preaction
Copy link
Owner

Auth::Basic is deprecated and not used by the main auth plugin. You want to read Yancy::Plugin::Auth::Password. I will add some documentation saying where to get the logout route for that plugin (the route's name is yancy.auth.password.logout). I will also add a generic logout method and route to the main plugin so folks can do what they wish. Thanks for finding this issue!

preaction added a commit that referenced this issue Apr 7, 2020
preaction added a commit that referenced this issue Apr 7, 2020
    [Added]

    - Added the ability for any "route" configuration to be a string.
      These will automatically be made into routes for you. Thanks
      @pavelsr for the suggestion! [Github #90]
    - Added "yancy.auth.logout" helper and route so that any authed user
      can be cleared out from any auth plugin. Thanks @pavelsr for the
      suggestion! [Github #91]

    [Fixed]

    - Fixed a bunch of missing/broken documentation (found by @pavelsr
      in #90, #91, and #92)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants