RSK
RSK

Reputation: 17516

Auth Component redirects automatically in cakePHP

After adding Auth component while accessing the home page it redirects to login page
ie., let www.domain.com is my url.
After adding the auth component when i try to access www.domain.com it redirects to www.domain.com/logins/login.

how can i avoid this initial redirection??

i already given a route as below

Router::connect('/', array(
    'controller' => 'pages', 'action' => 'display', 'home'
));

but no use
thankz in advance

Upvotes: 2

Views: 3979

Answers (3)

bancer
bancer

Reputation: 7525

In AppController::beforeFilter() add the following:

$this->Auth->allowedActions = array('display');

UPDATE: allowedActions are controller actions for which user validation is not required. http://api.cakephp.org/2.4/source-class-AuthComponent.html#228-234

Upvotes: 2

Nick
Nick

Reputation: 1331

You could also just add this code to your users controller to stop it from automatically redirecting, but like everyone else said, you should also allow display.

function beforeFilter() {
    ...
    $this->Auth->autoRedirect = false;
}

http://book.cakephp.org/view/395/autoRedirect

Upvotes: 2

Leo
Leo

Reputation: 6571

In your pages_controller.php (if you don't already have one in app/controllers, copy the one from cake/libs/controller:

function beforeFilter()
{
    parent::beforeFilter();
    $this->Auth->allow('*');
}

Upvotes: 3

Related Questions