Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
I am getting Notice error from auth
  • Hello there,

    When some user login using simpe auth, I get following error.

    Notice - Undefined index: driver in fuel/packages/auth/classes/auth.php on line 83

    When I looked at that package, following source code gives me error.

    ````
    $config = \Config::get('auth.'.$custom['driver'].'_config', array()); 
    ````

    Maybe, the source code should be written like following?

    ````
        // Driver is given as array key or just string in custom
        $custom = ! is_array($custom) ? array('driver' => $custom) : $custom;
        $config = isset($custom['driver']) ? \Config::get('auth.'.$custom['driver'].'_config', array()) : array();
        $config = array_merge($config, $custom);
    ````

    I am using simple auth and php is 7.2.24.
    If this is wrong way to fix it up, please correct me.
    Best regards,
  • Are you calling Auth::forge()? Without parameters?

    You don't need to do that, the default instance (configured in the auth.php config file) in instantiationed automatically when you call your first Auth method.

    If you don't need the default instance but a named instance, you need to pass that to Auth::forge().

    So the code is wrong in the sense that it should check for an empty $custom array, and throw an exception if that is the case. I'll put that on the todo.
  • HarroHarro
    Accepted Answer
    I'll change it to:

            // make sure custom is an array
            $custom = ! is_array($custom) ? array('driver' => $custom) : $custom;

            // driver must be set
            if (empty($custom['driver']) or ! is_string($custom['driver']))
            {
                throw new \AuthException('No auth driver specified when calling forge().');
            }

            // Driver is given as array key or just string in custom
            $config = \Config::get('auth.'.$custom['driver'].'_config', array());
            $config = array_merge($config, $custom);

  • Harro,

    Thank you very much for that.

    I always appreciate it.

    By the way, how I initialise it is as following.

    $auth = \Auth::instance();

    So, I do not call Auth::forge() in my program.

    Dose this help you to fix the issue?
  • Auth::instance() calls Auth::forge() if no instance exists, so that does exactly the same.

    So the fix I committed should also work.
  • Looked again, weird that you got this error in the first place.

    When Auth is called the first time, its init method will create the default instance based on your auth config. So when you call Auth::instance(), it should already exist, and forge() should not be called.

    This suggests there is an issue with your auth config.
  • Hello,

    Thanks for reply.

    Here is my auth config.

    <?php
    return array(
        'driver' => 'Simpleauth',
        'verify_multiple_logins' => false,
        'salt' => 'sdfsaafsafsdfsaf;sadfasfasdfsdfwew;fk',
        'iterations' => 10000,
    );

    Is there anything wrong with my config?
  • Looks fine to me.

    Then I don't know, I've checked one of my apps here that uses Simpleauth, and that works fine, without your issue.

    To test, I've added

    \Debug::dump($auth = \Auth::instance());

    as the first line of the action_index() of the homepage of this app, but that just returns the correct auth instance object.
  • Dear Harro,

    Thank you very much for helping me.

    I always appreciate it.

    I will check it out and if I find something wrong with my code and/or fuelphp, I let you know.

    Thanks :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion