CakeDC/Users gmail error

Warning (2) : Undefined array key "email" [in /home4/benqpsmy/public_html/devsys/vendor/cakedc/users/src/Model/Behavior/SocialBehavior.php, line 288]

Went through all the setup and installation, got all my apis and connecting to google. However it’s throwing and error message. So I debugged it some and at a lose or brain dead at the moment.

Traced it to the following function.

public function findExistingForSocialLogin(\Cake\ORM\Query\SelectQuery $query, array $options)
    {

        debug($options);
        debug($options['email']);

        exit;
        return $query->where([
            $this->_table->aliasField('email') => $options['email'],
        ]);
    }

Which debugs out to

ROOT/vendor/cakedc/users/src/Model/Behavior/SocialBehavior.php (line 285)
[
'options' => [
'email' => 'myemail@gmail.com',
],
]

Warning (2) : Undefined array key "email" [in /home4/benqpsmy/public_html/devsys/vendor/cakedc/users/src/Model/Behavior/SocialBehavior.php, line 286]
ROOT/vendor/cakedc/users/src/Model/Behavior/SocialBehavior.php (line 286)
null

Why is the first debug obviously showing the email key but the second is saying it’s null? Where did I go wrong or do?

You should learn to read the array correctly. You need to do

debug($options['options']['email']);

just because the variable is called $options doesn’t mean you automatically enter that inner array.

It’s been years since I’ve touched programming, last time I touched CakePHP was back in early version 3. I knew it had to be something stupid I was just over looking and not seeing what was right in front of me.

But anyways then there is a bug in the CakeDC/Users plugin.
\cakedc\users\src\Model\Behavior\SocialBehavior.php

    public function findExistingForSocialLogin(\Cake\ORM\Query\SelectQuery $query, array $options)
    {
        return $query->where([
            $this->_table->aliasField('email') => $options['email'],
        ]);
    }

Should be.

    public function findExistingForSocialLogin(\Cake\ORM\Query\SelectQuery $query, array $options)
    {
        return $query->where([
            $this->_table->aliasField('email') => $options['options']['email'],
        ]);
    }

Now back to playing with more code. Thanks!

I have created a Github Issue so the CakeDC Team can tackle that, thanks

@evansLY please let me know which version of CakeDC Users plugin are you using? I am working on the fix. Thank you

Sure, version 14.2.1

1 Like

@evansLY we released new version of CakeDC Users plugin that fixes the issue you encountered, Release 14.3.0 · CakeDC/users · GitHub

Thank you for reporting this.

1 Like