CakePHP Auth redirect problem

Today I lost a good two hours trying to find a solution to a ‘weird’ problem. I was having the issue – after implementing the Auth component in CakePHP 2.1 – that after logging in, the app didn’t redirect properly. At least that was what my browser was telling me. After my long Google search with only ‘ancient’ results for problems and bugs with the Auth system that didn’t exist anymore I finally had my Eureka moment.
After a successful log in the app should return me to the homepage of the app. Since this is just a static page to display. I needed to add the following lines to my PagesController class in /app/Controller/PagesController.php.

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

I hope that by sharing this I can at least help out a few other people that are running into this problem. It’s something really small and silly but it kept me busy for hours.

Author: Luc De Brouwer

Mild-mannered software engineer, Nine Inch Nails lover, gin drinker, cat person, and somewhat of a geek. Ron Swanson is my spirit animal.

3 thoughts on “CakePHP Auth redirect problem”

  1. I have this very same problem. Unfortunately I don’t have that PagesController ^^ I heard that authentication differs much from 1.3 and 2.x. Good find though : )

  2. Hi,

    Thanks for this useful tip.

    UPDATE: It appears that if you make any access to $this->Auth->redirect(), is sorta clears the value too. In my login(), I wanted to make a condition based on the redirect() so i used a function strstr() on $this->Auth->redirect(). That kept me up all night troubleshooting.

    It took me an extra hour (after finding your blog) to figure this out.

  3. i had a similar problem. Internet explorer not redirected after login (using auth). After some days i found the solution. The redirection of my domain not let to internet explorer create the session o similar (chrome o firefox works fine). Using the direct domain works in iexplorer too.

Comments are closed.