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
228 stars 56 forks source link

Change DB connection for tenant #155

Closed julianphp closed 1 year ago

julianphp commented 2 years ago

Hi, I am using this together with the https://tenancyforlaravel.com/ package, so I have the passport tables in each tenant and not in the main db, so if I try to use the auth.graphql schema, I get the error that it is pulling to the main db and not to the tenant specific one, is it possible to adjust the connection for that schema? Add, that there is no problem doing it manually and authenticating that it uses the passport, it is simply in the default schema of the auth.graphql.

joselfonseca commented 2 years ago

Under the hood the mutation just creates a request for the. Passport endpoint, this means that if you can do it with the Passport endpoint, you should be able to do it with the GraphQL interface. What you would need to do is override the resolver, extend the same resolver in your new one and customize the request to passport endpoint. See this: https://github.com/joselfonseca/lighthouse-graphql-passport-auth/blob/master/src/GraphQL/Mutations/BaseAuthResolver.php#L38

https://github.com/joselfonseca/lighthouse-graphql-passport-auth/blob/master/src/GraphQL/Mutations/BaseAuthResolver.php#L20

That is how the resolver gets the credentials.

joselfonseca commented 1 year ago

Closing due to inactivity.