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

I can't seem to update the password for a logged in user #113

Closed th3error closed 3 years ago

th3error commented 3 years ago

Hey @joselfonseca ,

I can really use your help on this one as well. I'm getting the following error:

local.ERROR: Trying to get property 'password' of non-object {"userId":1,"exception":"[object] (ErrorException(code: 0): Trying to get property 'password' of non-object at /home/daojin/oaaapay/vendor/joselfonseca/lighthouse-graphql-passport-auth/src/GraphQL/Mutations/UpdatePassword.php:27)

I did the following:

'route' => [ 'middleware' => [ \Illuminate\Cookie\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Nuwave\Lighthouse\Support\Http\Middleware\AttemptAuthentication::class, ], ],

My trace of the issue: https://github.com/joselfonseca/lighthouse-graphql-passport-auth/blob/077e1188e0d31fb6b56a650ff5e2b84043c18e66/src/GraphQL/Mutations/UpdatePassword.php#L27 The above is failing because this is: https://github.com/joselfonseca/lighthouse-graphql-passport-auth/blob/077e1188e0d31fb6b56a650ff5e2b84043c18e66/src/GraphQL/Mutations/UpdatePassword.php#L26

Do you have insights to what I might have gotten wrong or where can I dig to figure out the fix for this issue? Excuse me, I just recently started using Laravel and all these beautiful packages.

Much appreciated.

th3error commented 3 years ago

I figured out the problem: The user instance wasn't being created because even though I specified in my Schema to use the api guard, it didn't. It fell back to the default guard declared in auth.php which was web and that uses a session driver not passport.

After digging deeper, it turned out that AttemptAuthentication was looking for a passed in guard, if non found then it uses the declared guard lighthouse.guard.

I didn't even have that file, my only published config file was lighthouse-graphql-passport.php

All I did was publish the lighthouse.php file, set the guards on it and that sorted my issue.