authentication and forwarding to the correct place

39 views
Skip to first unread message

mjb152

unread,
May 4, 2015, 7:37:28 AM5/4/15
to mojol...@googlegroups.com
I'm using the authentication plugin, and I'm wondering what's the best method to remember the route I came from if I have to go to a login screen first. E.g if I'm not authenticated and come from either /route1 or /route2 , once I have entered my login details how can I get back to the correct place ?

Stefan Adams

unread,
May 4, 2015, 12:18:28 PM5/4/15
to mojolicious

On Mon, May 4, 2015 at 6:37 AM, mjb152 <martin...@gmail.com> wrote:
I'm using the authentication plugin, and I'm wondering what's the best method to remember the route I came from if I have to go to a login screen first. E.g if I'm not authenticated and come from either /route1 or /route2 , once I have entered my login details how can I get back to the correct place ?

I would store it in a client-side session:

get '/authentication_required' => sub ($c) {
  $c->session(page => $c->current_route);
  $c->redirect_to('login') unless $c->auth;
  $c->render(text => 'Success!');
};

get '/login' => sub ($c) {
  $c->redirect_to($c->session('page')) if $c->auth;
}

I significantly abstracted away the authentication details.

mjb152

unread,
May 4, 2015, 3:49:17 PM5/4/15
to mojol...@googlegroups.com
fantastic, thanks very much.
Reply all
Reply to author
Forward
0 new messages