Welcome Guest, Not a member yet? Register   Sign In
router query
#1

(This post was last modified: 11-15-2022, 09:09 AM by badger.)

A single redirect is causing two redirects and I can't figure out why. The code is intended to catch any uri containing "logout"  and send it to the auth controller which will do the logout process.
Many thanks for any help/advice
Bill

in Routes I have only the following
Code:
if(in_array('logout',explode('/',uri_string()))) {
    log_message('error', 'send to auth::loginout');
    $routes->post('/(:any)', 'Auth::loginout');
} else {
    $routes->get('/(:any)', '\App\Controllers\External\Home::index');
    log_message('error', 'authNotRequired "' . uri_string().'" FINISHED');
}
service('auth')->routes($routes);

In the Auth controller I have
Code:
    function loginout($par=false){
        // ..... the actual logout code will appear here but at the moment there is nothing
        log_message('error','auth::logged out now redirect to front');
        return redirect()->to('http://192.168.10.161/home');
    }

in my log file i see
Code:
    route begin -> `front/logout`
    send to auth::loginout
    auth::logged out now redirect to front                  <-- the auth controller now calls redirect to home
    route begin -> `home`                                          <-- this is where the router sees the uri for home
    authNotRequired "home" FINISHED                  <--  router is now finished with call to home
    route begin -> `home`                                          <-- but here the router has another call to home
    not logout
    authNotRequired "home" FINISHED

so the redirect to home in the Auth controller is called only once but the router sees it twice. The apache log confirms this
Code:
POST /front/logout
GET /home
GET /home

Stupid me. A moments reflection is worth a years experience. The second call to home was caused by the ajax call acting on the response.
Sorry
Reply
#2

Hey, that's how we learn.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB