Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.

### `<AuthState>` component

You can use the `<AuthState>` component to safely display auth-related data in your components without worrying about the rendering mode.
Expand Down
3 changes: 2 additions & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export default defineNuxtConfig({
auth: {
webAuthn: true,
atproto: true,
// loadStrategy: 'client-only'
// loadStrategy: 'none',
// loadStrategy: 'client-only',
},
icon: {
customCollections: [{
Expand Down
10 changes: 6 additions & 4 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand All @@ -59,7 +59,7 @@ declare module 'nuxt/schema' {

interface PublicRuntimeConfig {
auth: {
loadStrategy: 'server-first' | 'client-only'
loadStrategy: 'server-first' | 'client-only' | 'none'
}
}
}
Expand Down Expand Up @@ -96,8 +96,10 @@ export default defineNuxtModule<ModuleOptions>({
// 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'))
Expand Down
Loading