diff --git a/README.md b/README.md index 753cfd0d..d63ead36 100644 --- a/README.md +++ b/README.md @@ -609,6 +609,20 @@ export default defineNuxtConfig({ When using the `client-only` load strategy, the user session can still be manually fetched on the server side by calling `fetch` from the `useUserSession` composable. +### Disable session loading + +You may also choose to disable session loading entirely, with the `loadStrategy` option in your `nuxt.config.ts`: + +```ts +export default defineNuxtConfig({ + auth: { + loadStrategy: 'none' + } +}) +``` + +When using the `none` load strategy, the user session can still be manually fetched by calling `useUserSession().fetch()`. + ### `` component You can use the `` component to safely display auth-related data in your components without worrying about the rendering mode. diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index d4dd9bd7..b664883b 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -29,7 +29,8 @@ export default defineNuxtConfig({ auth: { webAuthn: true, atproto: true, - // loadStrategy: 'client-only' + // loadStrategy: 'none', + // loadStrategy: 'client-only', }, icon: { customCollections: [{ diff --git a/src/module.ts b/src/module.ts index 479915af..8c98152a 100644 --- a/src/module.ts +++ b/src/module.ts @@ -43,7 +43,7 @@ export interface ModuleOptions { * Session load strategy * @default 'server-first' */ - loadStrategy?: 'server-first' | 'client-only' + loadStrategy?: 'server-first' | 'client-only' | 'none' } declare module 'nuxt/schema' { @@ -59,7 +59,7 @@ declare module 'nuxt/schema' { interface PublicRuntimeConfig { auth: { - loadStrategy: 'server-first' | 'client-only' + loadStrategy: 'server-first' | 'client-only' | 'none' } } } @@ -96,8 +96,10 @@ export default defineNuxtModule({ // App addComponentsDir({ path: resolver.resolve('./runtime/app/components') }) addImports(composables) - addPlugin(resolver.resolve('./runtime/app/plugins/session.server')) - addPlugin(resolver.resolve('./runtime/app/plugins/session.client')) + if (options.loadStrategy !== 'none') { + addPlugin(resolver.resolve('./runtime/app/plugins/session.server')) + addPlugin(resolver.resolve('./runtime/app/plugins/session.client')) + } // Server addServerPlugin(resolver.resolve('./runtime/server/plugins/oauth')) addServerImportsDir(resolver.resolve('./runtime/server/lib/oauth'))