Skip to content

Commit

Permalink
Change SessionStrategy.end to be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Apr 8, 2024
1 parent b405f1b commit 4e501cd
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/no-session-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-6/core': major
---

Change `SessionStrategy.end` to be optional
2 changes: 1 addition & 1 deletion examples/custom-session-invalidation/keystone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function withSessionInvalidation (config: Config<Session>) {
// has the password changed since the session started?
if (new Date(session.data.passwordChangedAt) > new Date(session.startedAt)) {
// invalidate the session if password changed
await existingSessionStrategy.end({ context })
await existingSessionStrategy.end?.({ context })
return
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/lib/createGraphQLSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ export function createGraphQLSchema (
const graphQLSchema = getGraphQLSchema(
lists,
{
mutation: config.session
mutation: config.session?.end
? {
endSession: graphql.field({
type: graphql.nonNull(graphql.Boolean),
async resolve (rootVal, args, context) {
await context.sessionStrategy?.end({ context })
await context.sessionStrategy!.end!({ context })
return true
},
}),
Expand All @@ -127,5 +127,5 @@ export function createGraphQLSchema (
)

// merge in the user defined graphQL API
return config.graphql?.extendGraphqlSchema?.(graphQLSchema) ?? graphQLSchema
return config.graphql.extendGraphqlSchema?.(graphQLSchema) ?? graphQLSchema
}
2 changes: 1 addition & 1 deletion packages/core/src/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function storedSessions<Session> ({
if (!sessionId) return

await store.delete(sessionId)
await stateless.end({ context })
await stateless.end?.({ context })
},
}
}
1 change: 1 addition & 0 deletions packages/core/src/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function resolveDefaults (config: KeystoneConfig) {
...config.server,
cors,
},
session: config.session,
storage: {
...config?.storage
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type SessionStrategy<
> = {
get: (args: { context: KeystoneContext<TypeInfo> }) => Promise<Session | undefined>
start: (args: { context: KeystoneContext<TypeInfo>, data: Session }) => Promise<unknown>
end: (args: { context: KeystoneContext<TypeInfo> }) => Promise<unknown>
end?: (args: { context: KeystoneContext<TypeInfo> }) => Promise<unknown>
}

/** @deprecated */
Expand Down

0 comments on commit 4e501cd

Please sign in to comment.