'i cant directly going to login page with codeigniter 4, and using myth/auth

i tried to using codeigniter 4 and try using myth/auth, and i get a problem, if put restricted in my filters its not loading the login page

    public $aliases = [
    'csrf'     => CSRF::class,
    'toolbar'  => DebugToolbar::class,
    'honeypot' => Honeypot::class,
    'login'      => \Myth\Auth\Filters\LoginFilter::class,
    'role'       => \Myth\Auth\Filters\RoleFilter::class,
    'permission' => \Myth\Auth\Filters\PermissionFilter::class,

];

/**
 * List of filter aliases that are always
 * applied before and after every request.
 *
 * @var array
 */
public $globals = [
    'before' => [
        'honeypot',
        // 'csrf',
        'login'

    ],
    'after' => [
        'toolbar',
        // 'honeypot',
    ],
];

here my filters.php file

    <?php

namespace Myth\Auth\Filters;

use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;
use Config\App;
use phpDocumentor\Reflection\Types\Null_;

class LoginFilter implements FilterInterface
{
    /**
     * Verifies that a user is logged in, or redirects to login.
     *
     * @param RequestInterface $request
     * @param array|null $params
     *
     * @return mixed
     */
    public function before(RequestInterface $request, $arguments = NULL)
    {
        if (!function_exists('logged_in')) {
            helper('auth');
        }

        $current = (string)current_url(true)
            ->setHost('')
            ->setScheme('')
            ->stripQuery('token');

        $config = config(App::class);
        if ($config->forceGlobalSecureRequests) {
            # Remove "https:/"
            $current = substr($current, 7);
        }

        // Make sure this isn't already a login route
        if (in_array((string)$current, [route_to('login'), route_to('forgot'), route_to('reset-password'), route_to('register'), route_to('activate-account')])) {
            return;
        }

        // if no user is logged in then send to the login form
        $authenticate = service('authentication');
        if (!$authenticate->check()) {
            session()->set('redirect_url', current_url());
            return redirect('login');
        }
    }

    /**
     * @param RequestInterface  $request
     * @param ResponseInterface $response
     * @param array|null $arguments
     *
     * @return void
     */
    public function after(RequestInterface $request, ResponseInterface $response, $arguments = NULL)
    {
    }
}

this the loginFilter.php in myth/auth

    public $views = [
    // 'login'         => 'Myth\Auth\Views\login',
    // 'register'       => 'Myth\Auth\Views\register',

    'login'        => '\App\Views\Auth\login',
    'register'      => '\App\Views\Auth\register',
    'forgot'          => 'Myth\Auth\Views\forgot',
    'reset'        => 'Myth\Auth\Views\reset',
    'emailForgot'    => 'Myth\Auth\Views\emails\forgot',
    'emailActivation' => 'Myth\Auth\Views\emails\activation',
];

here my filters view in myth/auth

if i filtered the error getting happened like this and never going to login page

if i delete the

'login'

in filter config its not getting error



Solution 1:[1]

in my case,, i just adding base_url before route in my Login view

like

<form class="user" action="<?= base_url(); ?><?= route_to('login') ?>" method="post">

Solution 2:[2]

Go to app/Config/App.php

Change:

public $indexPage = 'index.php';

To:

public $indexPage = ' ';

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman
Solution 2 Ethan McTague