-
Built a custom login endpoint. For this endpoint I have graphql resolver that uses the localApi to login a user. However, I now need to set the cookie in the response. According to the documentation, Unfortunately, References:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It seems the default So to solve this, I had to set them again within the custom resolver like so: if (loginResult.token) {
const cookie = generatePayloadCookie({
collectionAuthConfig: userCollection.config.auth,
cookiePrefix: context.req.payload.config.cookiePrefix,
token: loginResult.token,
});
context.headers['Set-Cookie'] = cookie;
if (userCollection.config.auth.removeTokenFromResponses) {
delete loginResult.token;
}
} |
Beta Was this translation helpful? Give feedback.
It seems the default
payload.login
function sets cookies viacontext.headers['Set-Cookie']
, but this is not passed through to the custom resolver.So to solve this, I had to set them again within the custom resolver like so: