Extending keystone-6/auth sessionData #7312
-
Session DataExplanationIn KeystoneJS, the easiest and fun way to implement auth globally in the entire app is to inject data into the session in const { withAuth } = createAuth({
listKey: 'User',
identityField: 'email',
+ sessionData: `id name email
+ role {
+ ${permissionsList.join(' ')}
+ name
+ }
+ `,
secretField: 'password',
initFirstItem: {
fields: ['name', 'email', 'password']
}
}) Problem1: The query {
user(where: {id: "cl077jpxk0079c8gppukswjx5"}) {
id
name
username
email
role {
id
name
}
}
} What I want
I'd be glad if anyone shows me a way around it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can do this by augmenting the session config like this: const ksConfig = withAuth(
config({
// your keystone config
})
);
export default config({
...ksConfig,
session: {
...ksConfig.session!,
async get(args) {
const control = await args
.createContext({ sudo: true })
.query.Control.findOne({ where: { id: 'whatever' } });
return {
...ksConfig.session!.get(args),
control,
};
},
},
}); |
Beta Was this translation helpful? Give feedback.
You can do this by augmenting the session config like this: