Redirect in ControllerBase error

I'm creating a login session, when I check the login session in ControllerBase to return to the login page, the page is not working error.

class ControllerBase extends Controller
{
    public function initialize()
    {
        $session = $this->session;
        if(!$session->has('auth')) {
            return $this->response->redirect('user/login');
        }
    }
}

Can you share us your controllers code?

edited 16d ago

I assume by "not working" you mean the redirection isn't happening? What happens if you output $_SESSION? Do you see or not see the auth element? Have you tried outputing and exiting before your return statement - just to see if that condition is being satisfied?

Personally, I put this type of logic in beforeExecuteRoute() rather than initialize(). I can't really tell you why though...