File tree Expand file tree Collapse file tree 5 files changed +15
-7
lines changed Expand file tree Collapse file tree 5 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -2,9 +2,11 @@ import { config } from '@keystone-6/core';
22import { statelessSessions } from '@keystone-6/auth/session' ;
33import { createAuth } from '@keystone-6/auth' ;
44import { lists } from './schema' ;
5-
65import { isSignedIn } from './access' ;
76
7+ import { Session } from './types' ;
8+ import { TypeInfo } from '.keystone/types' ;
9+
810const sessionSecret = '-- DEV COOKIE SECRET; CHANGE ME --' ;
911const sessionMaxAge = 60 * 60 * 24 * 30 ; // 30 days
1012const sessionConfig = {
@@ -51,7 +53,7 @@ const { withAuth } = createAuth({
5153 sessionStrategy : statelessSessions ( sessionConfig ) ,
5254} ) ;
5355
54- export default withAuth (
56+ export default withAuth < TypeInfo < Session > > (
5557 config ( {
5658 db : {
5759 provider : 'sqlite' ,
Original file line number Diff line number Diff line change @@ -228,11 +228,12 @@ export function printGeneratedTypes(
228228 '}' ,
229229 `export type Context = import('@keystone-6/core/types').KeystoneContext<TypeInfo>;` ,
230230 '' ,
231- 'export type TypeInfo = {' ,
231+ 'export type TypeInfo<Session = any> = {' ,
232232 ` lists: {` ,
233233 ...listsTypeInfo ,
234234 ` };` ,
235235 ` prisma: import('.prisma/client').PrismaClient;` ,
236+ ` session: Session;` ,
236237 `};` ,
237238 `` ,
238239 // we need to reference the `TypeInfo` above in another type that is also called `TypeInfo`
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export type KeystoneContext<TypeInfo extends BaseKeystoneTypeInfo = BaseKeystone
1414 graphql : KeystoneGraphQLAPI ;
1515 sudo : ( ) => KeystoneContext < TypeInfo > ;
1616 exitSudo : ( ) => KeystoneContext < TypeInfo > ;
17- withSession : ( session : any ) => KeystoneContext < TypeInfo > ;
17+ withSession : ( session : TypeInfo [ 'session' ] ) => KeystoneContext < TypeInfo > ;
1818 withRequest : ( req : IncomingMessage , res ?: ServerResponse ) => Promise < KeystoneContext < TypeInfo > > ;
1919 prisma : TypeInfo [ 'prisma' ] ;
2020 files : FilesContext ;
@@ -27,8 +27,8 @@ export type KeystoneContext<TypeInfo extends BaseKeystoneTypeInfo = BaseKeystone
2727 */
2828 initialisedLists : Record < string , InitialisedList > ;
2929 } ;
30- getSession ?: ( args : { context : KeystoneContext } ) => Promise < unknown | undefined > ;
31- session ?: any ;
30+ getSession ?: ( args : { context : KeystoneContext } ) => Promise < TypeInfo [ 'session' ] | undefined > ;
31+ session ?: TypeInfo [ 'session' ] ;
3232} ;
3333
3434// List item API
Original file line number Diff line number Diff line change @@ -28,4 +28,8 @@ export type BaseListTypeInfo = {
2828export type KeystoneContextFromListTypeInfo < ListTypeInfo extends BaseListTypeInfo > =
2929 KeystoneContext < ListTypeInfo [ 'all' ] > ;
3030
31- export type BaseKeystoneTypeInfo = { lists : Record < string , BaseListTypeInfo > ; prisma : any } ;
31+ export type BaseKeystoneTypeInfo = {
32+ lists : Record < string , BaseListTypeInfo > ;
33+ prisma : any ;
34+ session : any ;
35+ } ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ const someContext: KeystoneContext<{
88 ListOrSingleton : BaseListTypeInfo ;
99 } ;
1010 prisma : any ;
11+ session : any ;
1112} > = undefined ! ;
1213
1314someContext . query . Singleton . findOne ( { } ) ;
You can’t perform that action at this time.
0 commit comments