joselfonseca / lighthouse-graphql-passport-auth

Add GraphQL mutations to get tokens from passport for https://lighthouse-php.com/
https://lighthouse-php-auth.com/
MIT License
229 stars 56 forks source link

SocialLogin - RequestGuard::onceUsingId does not exist #82

Closed a-zog closed 4 years ago

a-zog commented 4 years ago

Hi,

First of all, thank you for this package, it's very helpful.

I've tried to use the social login GQL query as mentioned in the documentation. https://lighthouse-passport-auth.web.app/docs/default-schema/

But I've got this error: "message": "Method Illuminate\\Auth\\RequestGuard::onceUsingId does not exist." at: HasSocialLogin.php > Auth::onceUsingId($user->id)

I found that it would work with Auth::guard('web')->onceUsingId($user->id) but then it would not sync with SocialLogin@solve because it's still using the default guard (API).

This is a preview of the api middlewares used:

 protected $middlewareGroups = [
         ...
        'api' => [
            'throttle:60,1',
            'bindings',
            \Barryvdh\Cors\HandleCors::class,
            \App\Http\Middleware\UseApiAuthGuard::class,
        ],
];

I may doing it wrong. I would appreciate some guidance if it were the case.

Thank you in advance

joselfonseca commented 4 years ago

Is web your default guard?

a-zog commented 4 years ago

API is set to be the default

joselfonseca commented 4 years ago

yeah, that may be the problem, We actually never set the default to api so maybe that is why I never encounter this error. We have 2 options here.

  1. Set the default back to web and use guard(with: ['api']) (this is what we usually do)
  2. Override the trait method and use the Auth::guard('web')->onceUsingId($user->id) This is done just because we need to set the logged in user to retreive it later in the pipeline.

I still want to see a better way to do this but for now these would be the options.

a-zog commented 4 years ago

Okey, thank you for your help

joselfonseca commented 4 years ago

no problem, closing this.

rushairer commented 3 years ago

I have the same problem.

How to fix this bug?

Thanks! @joselfonseca

joselfonseca commented 3 years ago

Hi @rushairer is not actually a bug, but in the latest version I changed that to use another method to set the user. you can update to latest keeping in mind there is a breaking change in how social login works, or override the method and use Auth::setUser()

https://github.com/joselfonseca/lighthouse-graphql-passport-auth/blob/master/src/HasSocialLogin.php#L53

rushairer commented 3 years ago

@joselfonseca Thanks! I am updating my packages.