Cake 4.5 using CakeDC/Users Missing Route

I would like to redirect users to “/orders” after they have logged in. But when I call up the login page I get the following error message:

Missing Route: A route matching "array ( 'controller' => 'Orders', 'action' => 'index', 'plugin' => 'CakeDC/Users', '_ext' => NULL, )" could not be found.

But I can’t find out what the reason could be

config/routes

$routes->scope('/', function (RouteBuilder $builder) {
        $builder->connect('/orders', ['controller' => 'Orders', 'action' => 'index']);
        $builder->connect('/pages/*', 'Pages::display');
        $builder->fallbacks();
    });

config/users

<?php
$config = [
    'Users' => [
        'Social' => [
            'login' => false,
            'validateSocialAccount' => false,
        ],
    ],
    'OneTimePasswordAuthenticator.login' => false,
];

return $config;

config/permissions

return [
    'CakeDC/Auth.permissions' => [
        [
            'role' => '*',
            'plugin' => 'DebugKit',
            'controller' => '*',
            'action' => '*',
            'bypassAuth' => true,
        ],
        [
            'role' => '*',
            'controller' => 'Users',
            'action' => ['login', 'logout'],
            'bypassAuth' => true,
        ],
        [
            'role' => 'admin',
            'controller' => '*',
            'action' => '*',
        ],
        [
            'role' => 'user',
            'controller' => 'Orders',
            'action' => ['index'],
        ],
        [
            'role' => 'user',
            'controller' => 'Users',
            'action' => ['edit'],
            'allowed' => function (App\Model\Entity\User $user, $role, ServerRequest $request) {
                $userId = Hash::get($request->getAttribute('params'), 'pass.0');

                if (!empty($userId)) {
                    return $userId === $user['id'];
                }

                return false;
            },
        ],
    ],
];

Application

    public function bootstrap(): void
    {
        // Call parent to load bootstrap from files.
        parent::bootstrap();

        if (PHP_SAPI === 'cli') {
            $this->bootstrapCli();
        } else {
            FactoryLocator::add(
                'Table',
                (new TableLocator())->allowFallbackClass(false)
            );
        }

        /*
         * Only try to load DebugKit in development mode
         * Debug Kit should not be installed on a production system
         */
        if (Configure::read('debug')) {
            Configure::write('DebugKit.safeTld', ['de', 'com']);
            Configure::write('DebugKit.variablesPanelMaxDepth', 10);
            $this->addPlugin('DebugKit');
        }

        // Load more plugins here
        // https://github.com/CakeDC/users/blob/11.next-cake4/Docs/Documentation/Installation.md#load-the-plugin
        $this->addPlugin(\CakeDC\Users\Plugin::class);
        Configure::write('Users.config', ['users']);
    }

    public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
    {
        $middlewareQueue
            ->add(new ErrorHandlerMiddleware(Configure::read('Error'), $this))
            ->add(new AssetMiddleware([
                'cacheTime' => Configure::read('Asset.cacheTime'),
            ]))
            ->add(new RoutingMiddleware($this))
            ->add(new BodyParserMiddleware())
            ->add(new CsrfProtectionMiddleware([
                'httponly' => true,
            ]));

        return $middlewareQueue;
    }

Somewhere, you are specifying ['controller' => 'Orders', 'action' => 'index'] as the thing to redirect to. But it’s the users plugin that’s doing the redirect, so it’s defaulting to looking for it in that plugin. Set it to ['controller' => 'Orders', 'action' => 'index', 'plugin' => false] to override that.

thanks, that helped to get the login workin, but after i log in i get this error thrown:

Table class for alias Users could not be found.

That’s a completely different problem, which you should post a new question for. When you do, you should include details like the stack trace and the specific code that’s causing the error, because the error message itself is nowhere near enough to go on.

@Zuluru After I restarted the server and cleared all caches, the problem with the table alias is gone and the assignment of users to orders works.
But now the following error is thrown for the following routes

A route matching "array ( 'controller' => 'Orders', 'action' => 'index', 'plugin' => 'CakeDC/Users', '_ext' => NULL, )" could not be found.

at

/users/edit/ID
/users/view/ID

config/routes

<?php

use Cake\Routing\Route\DashedRoute;
use Cake\Routing\RouteBuilder;

return static function (RouteBuilder $routes) {
    $routes->setRouteClass(DashedRoute::class);
    $routes->scope('/', function (RouteBuilder $builder) {
        $builder->connect('/', ['controller' => 'Orders', 'action' => 'index', 'plugin' => false]);
        $builder->connect('/pages/*', 'Pages::display');
        $builder->fallbacks();
    });
};

config/users

<?php
$config = [
    'Users' => [
        'table' => 'CakeDC/Users.Users',
        'controller' => 'CakeDC/Users.Users',
        'Social' => [
            'login' => false,
            'validateSocialAccount' => false,
        ],
    ],
    'OneTimePasswordAuthenticator' => [
        'login' => false,
    ],
    'Auth' => [
        'AuthenticationComponent' => [
            'load' => true,
            'loginRedirect' => '/orders',
            'requireIdentity' => false,
        ],
    ],
];

return $config;

What could be the reason for this?

It could be exactly what I said above when you mentioned that error. You need 'plugin' => false wherever you’re generating those order URLs.

but i already added this to routes

$builder->connect('/', ['controller' => 'Orders', 'action' => 'index', 'plugin' => false]);

therefor i don´t know where to put this too

It’s not the route that’s missing. Something somewhere is trying to generate a route (e.g. for a link) that does not have the 'plugin' => false specified, and it’s failing as a result.

Sorry, I misunderstood you. There were a few links that had to be adjusted. It works now, thank you!