Reputation: 14008
I'm using the auth component and I don't want the login page to be accessible once the user has logged in, it should only be accessed by anonymous users. What can I put in my login method to accomplish this? I've tried this:
if (isset($this->Auth->user('id')) {
$this->redirect('/profile/');
}
But I get the following error:
Fatal error: Can't use method return value
Upvotes: 1
Views: 5256
Reputation: 20267
The Auth Component actually provides a method for checking if the user is logged in.
$this->Auth->loggedIn();
There are a half dozen other ways to check, but this one is best because it abstracts away the implementation of the authentication session. Also, it's easier to read.
Upvotes: 11
Reputation: 12873
if ($this->Session->check('Auth.User')){
$this->redirect('/profile/');
}
Upvotes: 3