Welcome Guest, Not a member yet? Register   Sign In
public $filters except login page

I work with filter method for check admin users authentication like this:

PHP Code:
class Filters extends BaseConfig
// Makes reading things below nicer,
    // and simpler to change out script that's used.
public $aliases = [
'csrf'     => \CodeIgniter\Filters\CSRF::class,
'toolbar'  => \CodeIgniter\Filters\DebugToolbar::class,
'honeypot' => \CodeIgniter\Filters\Honeypot::class,
'auth'     => \App\Filters\Auth::class,

// Always applied before every request
public $globals = [
'before' => [

'after'  => [

// Works on all of a particular HTTP method
    // (GET, POST, etc) as BEFORE filters only
    //     like: 'post' => ['CSRF', 'throttle'],
public $methods = [];

// List filter aliases and any before/after uri patterns
    // that they should run on, like:
    //    'isLoggedIn' => ['before' => ['account/*', 'profiles/*']],
public $filters = [
        'auth' => ['before' => 'admin/*'],

public filter work for all admin uri (admin/roles  - admin/users - admin/login) but i need to except admin/login because with this method i can not see login page and see browser error:

This page isn’t working right now
ci4.local redirected you too many times.

how do fix this problem?! thanks

Yep, it's called "except": https://codeigniter4.github.io/userguide...ml#globals

You need to add condition inside AuthFilter, I do it like this
PHP Code:
// get the current URL path, like "auth/login"
$currentURIPath "/{$request->uri->getPath()}";

// check if the current path is auth path, just return true
// don't forget to use named routes to simplify the call
if (in_array($currentURIPath, [route_to('auth'), route_to('api.auth.login')])) {

I hope this can help.

It's work fine with v4.0.4

My Default Controller is Login on global I add my authenticationfilter and add except for all Login controller 'login/*' and '/'

public $aliases = [
'csrf' => \CodeIgniter\Filters\CSRF::class,
'toolbar' => \CodeIgniter\Filters\DebugToolbar::class,
'honeypot' => \CodeIgniter\Filters\Honeypot::class,
'authenticationfilter' => \App\Filters\AuthenticationFilter::class,

// Always applied before every request
public $globals = [
'before' => [
'authenticationfilter'=> ['except' => ['login/*', '/']],
// 'csrf',
'after' => [
There are those who tell lies with meaning behind them and those meaning less lies!

Theme © iAndrew 2016 - Forum software by © MyBB