# Redirecting to current page after logged in using cakephp 3.4.7

**URL:** <https://discourse.cakephp.org/t/redirecting-to-current-page-after-logged-in-using-cakephp-3-4-7/2615>\
**Category:** Need Help\
**Created:** [May 24, 2017, 11:53am UTC](https://discourse.cakephp.org/t/redirecting-to-current-page-after-logged-in-using-cakephp-3-4-7/2615 "2017-05-24T11:53:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashok](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@ashok](https://discourse.cakephp.org/u/ashok)\
**Post date:** [May 24, 2017, 11:53am UTC](https://discourse.cakephp.org/t/redirecting-to-current-page-after-logged-in-using-cakephp-3-4-7/2615/1 "2017-05-24T11:53:41Z")

</div>

Recently I have upgraded cakephp 3.3.4 to cakephp 3.4.7, in old version If loggedin in current page it’s redirecting to current page only as I aspect, but after upgraded It’s redirecting into home page, I don’t know what’s the problem. please help me out here

In AppController:

```
public function initialize()
{
    parent::initialize();
    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
    $this->loadComponent('Auth', [
        'authorize' => ['Controller'],
        'authenticate' => [
            'Form' => [
                'fields' => [
                    'username' => 'email',
                    'password' => 'password'
                ],
                'scope' => ['userStatus' => '1']
            ]
        ],
        'loginAction' => [
            'controller' => 'Users',
            'action' => 'login'
        ],
        'unauthorizedRedirect' => $this->referer(),
        'logoutRedirect' => [
                'controller' => 'Users',
                'action' => 'login'
        ]
    ]);
}

```

login function:

```
public function login()
{
    if($this->Auth->user()){
        $this->Flash->error(__('You are already logged in!'));
        return $this->redirect($this->Auth->redirectUrl());
    }
    else{
        if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        }
        $this->Flash->error('Your username or password is incorrect.');
      }
   }
}
```

---

<div class="post-metadata">

**Author:** ![Diego](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/diego/32/296_2.png) [@Diego](https://discourse.cakephp.org/u/Diego)\
**Post date:** [May 24, 2017, 12:19pm UTC](https://discourse.cakephp.org/t/redirecting-to-current-page-after-logged-in-using-cakephp-3-4-7/2615/2 "2017-05-24T12:19:46Z")

</div>

Try set this option in the Auth component and test if the problem persist:

`'loginRedirect' => ['controller' => 'pages', 'action' => 'dashboard', 'prefix' => false],`

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [May 24, 2017, 1:45pm UTC](https://discourse.cakephp.org/t/redirecting-to-current-page-after-logged-in-using-cakephp-3-4-7/2615/3 "2017-05-24T13:45:32Z")

</div>

[https://book.cakephp.org/3.0/en/controllers/components/authentication.html#redirecting-users-after-login](https://book.cakephp.org/3.0/en/controllers/components/authentication.html#redirecting-users-after-login)
