Authentication plugin getting redirected after successful login

Currently have an issue: Im migrating from authcomponent to the authentication plugin and for some reason, after a successful login, im still getting redirected back to the login page.

$result = $this->Authentication->getResult();
if ($result->isValid()) {
//some logic for updating some database fields (last login etc)

    $target = $this->Authentication->getLoginRedirect();
     if (!$target) {
         $target = ['controller' => 'Accounts', 'action' => 'index'];
         return $this->redirect($target);
//wrong password error logic here

After logging in, it starts a redirect loop between accounts/ and users/login.
If i change the unAuthenticatedRedirect to something random, it still redirect to login, so its seems to be authenticated?

AuthenticationService setup:

        $authenticationService = new AuthenticationService([
            'unauthenticatedRedirect' => Router::url('/users/login'),
            'loginRedirect' => Router::url('/accounts'),
            'logoutRedirect' => Router::url('/users/login'),
            'queryParam' => 'redirect',
//authenticators and identifiers....

Everything is based off either the CMS tutorial or the migration guide.

To me this seems like accounts/ is not allowed to be accessed as a logged in user.
Do you have the authorization plugin enabled as well?

No, i don’t have the authorization plugin enabled.

Also I just noticed: Some of your config values for the AuthenticationService aren’t present like the loginRedirect or logoutRedirect.
See authentication/AuthenticationService.php at 2.x · cakephp/authentication · GitHub

I would debug the AuthenticationMiddleware in authentication/AuthenticationMiddleware.php at 2.x · cakephp/authentication · GitHub so you know what exactly is the problem on your side. Can’t really tell with the information given till now.

Ok, thanks for your help, i’ll look into it more.