I am trying to implement authentication in a custom resolver function but to achieve that, I must be able to set a cookie on the response.
I found the following docs on what data is available, unfortunately, I see no way to access the response object nor the response headers. How would this be achievable?
2
Answers
If you want to set something in the response of the graphQL you can use EndRequestEvent.
I recommend you to keep the HTTP layer separate from the GraphQL layer. That means:
In my experience, authentication work best when handled exclusively on the HTTP layer – use standard Laravel mechanisms such as guards, described in https://laravel.com/docs/authentication and tie it into your Lighthouse server through middleware such as
NuwaveLighthouseHttpMiddlewareAttemptAuthentication
.