Skip to content

Remove session end/start from core and provide generic request and response Headers on context instead of node-specific req/res#9579

Draft
emmatown wants to merge 1 commit intopush-oynxlqvlmxwlfrom
session-updates
Draft

Remove session end/start from core and provide generic request and response Headers on context instead of node-specific req/res#9579
emmatown wants to merge 1 commit intopush-oynxlqvlmxwlfrom
session-updates

Conversation

@emmatown
Copy link
Copy Markdown
Member

@emmatown emmatown commented Apr 2, 2025

The current Keystone session API that is provided to config looks like this

export type SessionStrategy<
  Session,
  TypeInfo extends BaseKeystoneTypeInfo = BaseKeystoneTypeInfo,
> = {
  get: (args: { context: KeystoneContext<TypeInfo> }) => Promise<Session | undefined>
  start: (args: { context: KeystoneContext<TypeInfo>; data: Session }) => Promise<unknown>
  end: (args: { context: KeystoneContext<TypeInfo> }) => Promise<unknown>
}

and then it's provided on the KeystoneContext as sessionStrategy. @keystone-6/core only uses the get function though. The start and end functions are only either used by @keystone-6/auth or they're called directly by users in their resolvers or etc. If people are using next-auth, passport or etc. these start and end functions go unused since the session is started/ended elsewhere.

So this PR replaces the SessionStrategy with a getSession function in @keystone-6/core and the SessionStrategy API and statelessSession and storedSessions implementations have been moved into @keystone-6/auth.

Combined with #9578, this also improves the type-safety & flexibility around sessions with @keystone-6/auth accepting a getSession function like @keystone-6/core does except that it's provided data with the item id that the session is for.

  getSession: ({ context, data }) =>
    context.query.User.findOne({
      where: { id: data.itemId },
    }),

Supersedes #8097

Stacked on #9578

@emmatown emmatown changed the title Remove session end/start from core and provide generic fetch-style request and response on context instead of node-specific Remove session end/start from core and provide generic fetch-style request and response on context instead of node-specific req/res Apr 2, 2025
@socket-security
Copy link
Copy Markdown

socket-security bot commented Apr 2, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​express-session@​1.18.21001007381100
Added@​as-integrations/​next@​3.2.0991009889100

View full report

@emmatown emmatown force-pushed the session-updates branch 2 times, most recently from 7d7e4bc to c9db964 Compare April 2, 2025 02:43
@emmatown emmatown changed the title Remove session end/start from core and provide generic fetch-style request and response on context instead of node-specific req/res Remove session end/start from core and provide generic request and response Headers on context instead of node-specific req/res Apr 2, 2025
…quest and response on context instead of node-specific
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant