On CakePHP 2.2 using AuthComponent, what is the best way to redirect a user from ‘/’ to ‘/users’ if they are already authenticated? All of my searches have just turned up information about the AuthComponent’s loginRedirect and related. I read a post detailing changing the Routes (in 1.x), but I wasn’t sure if this was still the best way. I could also insert
if($path[0] == 'home' && $this->Session->check('Auth.User')){
$this->redirect('/users/');
}
in PageController::display(), but again, not sure if this is the most desirable method
The index page for this application will simply be a page asking the user to sign up or log in, so it is of little importance to members already logged in.
Edit:
After revisiting the beforeFilter() method, I came up with
public function beforeFilter() {
$this->Auth->allow('*');
if($this->request->params['pass'][0] == 'home' && $this->Session->check('Auth.User'))
$this->redirect('/users');
}
but this seems really static.
Proper way is to redirect user from the controller’s beforeFilter method. Redirecting from .ctp file is not good.
// In PagesController.cpp
Some sort of similar:
CakePHP Auth component redirect issue