You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically, I am trying to create an authentication through cookie instead of storing the JWT in the localStorage.
I have a REST API endpoint (built with Loopback4) for login and I am making a graphql request from the frontend for user login.
On successful login, I am setting the cookie in the response. Note that this is happening in the controller of my REST API.
response.cookie('SESSIONID', 'something', {...})
I understand that openapi-to-graphql works in a way that the graphql request is converted to make a call to the REST API and then converts back the response into a graphql response.
However, seems like the cookie in the header got lost in the process. Even any header that I set in the login process is not carried to the graphql response header.
In a standalone GraphQL server with typeDefs and resolver, we can pass the context into the resolver and set the cookie in th response.
In the getResolver function, could we not simply set the cookie since variable resolveData hold the response headers data?
Example of modification.
if (response.headers.get('content-type').includes('application/json')) {
let responseBody;
try {
responseBody = JSON.parse(body);
}
catch (e) {
const errorString = `Cannot JSON parse response body of ` +
`operation ${operation.operationString} ` +
`even though it has content-type 'application/json'`;
httpLog$1(errorString);
throw new Error(errorString);
}
resolveData.responseHeaders = {};
response.headers.forEach((val, key) => {
resolveData.responseHeaders[key] = val;
// add this
context.res.setHeader(key, val)
});
...
}
Can someone help to point me in the right direction?
The text was updated successfully, but these errors were encountered:
Hi,
Basically, I am trying to create an authentication through cookie instead of storing the JWT in the localStorage.
I have a REST API endpoint (built with Loopback4) for login and I am making a graphql request from the frontend for user login.
On successful login, I am setting the cookie in the response. Note that this is happening in the controller of my REST API.
I understand that openapi-to-graphql works in a way that the graphql request is converted to make a call to the REST API and then converts back the response into a graphql response.
However, seems like the cookie in the header got lost in the process. Even any header that I set in the login process is not carried to the graphql response header.
In a standalone GraphQL server with
typeDefs
andresolver
, we can pass the context into the resolver and set the cookie in th response.In the
getResolver
function, could we not simply set the cookie since variableresolveData
hold the response headers data?Example of modification.
Can someone help to point me in the right direction?
The text was updated successfully, but these errors were encountered: