yii2-usuario icon indicating copy to clipboard operation
yii2-usuario copied to clipboard

Argument 1 passed to Da\User\Event\SocialNetworkAuthEvent::__construct() must be an instance of Da\User\Model\SocialNetworkAccount, bool given

Open dantart opened this issue 4 years ago • 3 comments

When I use for FIRST time it works perfectly, and save record in the database.

But when I try to use it as second time (with an already registered user), I always have this error when coming back from the social network:

Argument 1 passed to Da\User\Event\SocialNetworkAuthEvent::__construct() must be an instance of Da\User\Model\SocialNetworkAccount, bool given

The URL at top is like this (in case of Google, but it happens with all social networks) https://mydomain.com/user/security/authclient/google?state=XXXXXXXXXXXXXXXXXXXXXXXX&code=XXXXXXXXXXXXXXXXXXXXXXXX&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&authuser=7&prompt=none#

Why is this?

It starts with the "SocialNetworkAuthEvent" object, but in some point , it's "lost" with a "false":

(this screenshot is with LinkedIn ... as I said, it happens with all social networks)

Captura de pantalla 2021-01-21 a las 16 22 12

dantart avatar Jan 21 '21 14:01 dantart

Guys, this is insane ... after debugging a lot I fixed it with this:

adding return $account;

in line 95 of https://github.com/2amigos/yii2-usuario/blob/master/src/User/Service/SocialNetworkAccountConnectService.php

if not, that function returns "false" (when the account already exists in the social_account table), and that "false" is tried to be injected in the Da\User\Event\SocialNetworkAuthEvent class, therefore, the above error appears.

Can't believe this is happen just to me.

dantart avatar Jan 21 '21 16:01 dantart

I never used social auth, but indeed your fix looks correct...

maxxer avatar Jan 21 '21 17:01 maxxer

Same happened here, worked with this fix in PHP 7.4.12.

Guys, this is insane ... after debugging a lot I fixed it with this:

adding return $account;

in line 95 of https://github.com/2amigos/yii2-usuario/blob/master/src/User/Service/SocialNetworkAccountConnectService.php

if not, that function returns "false" (when the account already exists in the social_account table), and that "false" is tried to be injected in the Da\User\Event\SocialNetworkAuthEvent class, therefore, the above error appears.

Can't believe this is happen just to me.

Jonyx4 avatar Jun 16 '21 12:06 Jonyx4