Skip to content

Opt-out of session plugin #450

@IlyaSemenov

Description

@IlyaSemenov

I would like to be able to opt-out of forced client-side session fetch that happens on each page load:

addPlugin(resolver.resolve('./runtime/app/plugins/session.client'))

if (!nuxtApp.payload.serverRendered) {
await useUserSession().fetch()
}

I have two specific use cases in mind for avoiding the default plugin:

  1. I would like to optimize no-SSR data fetch as explained here Get rid of extra HTTP request with ssr: false #449 (if you decide that approach is too magicky to land in the core, at least allow this to be implemented with a user-land plugin).
  2. For some projects, I also would like to deliver non-JSON-serializable user data. For instance, I have a project involving e2e encryption, where the auth session brings WebCrypto keys (Uint8Array's). Most of the client-server communication is performed via tRPC and a custom serializer that passes binary data transparently, but specifically for the auth session I had to come up with ugly boilerplate and intermediary types. I would like to either fetch the session data with a custom tRPC endpoint, or perhaps combine this with (1) and deliver this with a custom Nuxt payload.

How I see it, it will be a simple option in nuxt.config.ts:

export default defineNuxtConfig({
  session: {
    plugin: false // or injectPlugin: false
  }
})

I can come up with a PR if you generally approve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions