I'm trying use session in strapi. But i can't use save or use session.
import { Strapi } from '@strapi/strapi'
export default ({ strapi }: { strapi: Strapi }) => ({
search: {
resolve: async (obj, { name }, context) => {
console.log(context.session, context.state.user)
context.session = context.state.user // <---
return await strapi.service('api::printful.product').search({ name })
}
}
})
I tried use like this session. But when send second request context.session
still undefinied
.
And my config/middleware.ts
file look like this.
export default ({ env }) => ({
settings: {
session: {
enabled: true,
client: 'cookie',
key: 'strapi.sid',
prefix: 'strapi:sess:',
secretKeys: env.array('APP_KEYS'),
httpOnly: true,
maxAge: 24 * 60 * 60 * 1000, // 24 hours
overwrite: true,
signed: false,
rolling: false
},
// cookieParser: {
// enabled: true
// }
}
})
Strapi Version : 4.21.0
Node Version : 18.20.2
What am I doing wrong?
When i set context.session in GQL resolvers, context.session not setting. Because in resolver, not a real controller. Because context object is a copy. When i set context.session in controller its working!