Mojolicious redirect to different path under 'under' with userinfo

336 Views Asked by At

I have two routes

One under 'under' which does the authentication from 'userinfo' and another one which is meant for public

post '/public' => sub {
    my $c = shift;
    my $submitter = $c->param('submitter');
    my $password = $c->param('password');

    my $url = Mojo::URL->new('/v1/time')->userinfo("$submitter:$password");

    $c->redirect_to( $url );
};

under(sub {
    my $c = shift;
    $c->app->log->debug( Dumper($c->req->url) );
    my ($un, $pw) = split ':', $c->req->url->to_abs->userinfo;
    # do authentication here
    # .....  
});

any ['GET', 'POST'] => '/v1/time' => sub {
    shift->render(json => { now => scalar(localtime) });
};

Why I can't seem to pass the userinfo data to the new url?

Result from Data::Dumper is

bless( {
                 'base' => bless( {
                                    'scheme' => 'http',
                                    'port' => 'xxxxx',
                                    'host' => 'xxxxxxxxx.corpnet2.com'
                                  }, 'Mojo::URL' ),
                 'query' => bless( {
                                     'pairs' => []
                                   }, 'Mojo::Parameters' ),
                 'path' => bless( {
                                    'charset' => 'UTF-8',
                                    'path' => '/v1/time'
                                  }, 'Mojo::Path' )
               }, 'Mojo::URL' );
1

There are 1 best solutions below

0
On BEST ANSWER