File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ declare module 'nuxt/schema' {
50
50
* Session configuration
51
51
*/
52
52
session : SessionConfig
53
+ disableAuthAutoLoad ?: boolean
53
54
}
54
55
}
55
56
@@ -495,5 +496,10 @@ export default defineNuxtModule<ModuleOptions>({
495
496
tokenURL : '' ,
496
497
userURL : '' ,
497
498
} )
499
+
500
+ // Publicly expose disableAuthAutoLoad if needed
501
+ if ( runtimeConfig . disableAuthAutoLoad && runtimeConfig . public . disableAuthAutoLoad === undefined ) {
502
+ runtimeConfig . public . disableAuthAutoLoad = runtimeConfig . disableAuthAutoLoad
503
+ }
498
504
} ,
499
505
} )
Original file line number Diff line number Diff line change @@ -3,14 +3,16 @@ import {} from 'nuxt/app'
3
3
import { defineNuxtPlugin , useUserSession , useError } from '#imports'
4
4
5
5
export default defineNuxtPlugin ( async ( nuxtApp ) => {
6
- if ( ! nuxtApp . payload . serverRendered ) {
7
- await useUserSession ( ) . fetch ( )
8
- }
9
- else if ( Boolean ( nuxtApp . payload . prerenderedAt ) || Boolean ( nuxtApp . payload . isCached ) ) {
10
- // To avoid hydration mismatch
11
- nuxtApp . hook ( 'app:mounted' , async ( ) => {
6
+ if ( ! nuxtApp . $config . public . disableAuthAutoLoad ) {
7
+ if ( ! nuxtApp . payload . serverRendered ) {
12
8
await useUserSession ( ) . fetch ( )
13
- } )
9
+ }
10
+ else if ( Boolean ( nuxtApp . payload . prerenderedAt ) || Boolean ( nuxtApp . payload . isCached ) ) {
11
+ // To avoid hydration mismatch
12
+ nuxtApp . hook ( 'app:mounted' , async ( ) => {
13
+ await useUserSession ( ) . fetch ( )
14
+ } )
15
+ }
14
16
}
15
17
16
18
if ( localStorage . getItem ( 'temp-nuxt-auth-utils-popup' ) ) {
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ export default defineNuxtPlugin({
8
8
async setup ( nuxtApp ) {
9
9
// Flag if request is cached
10
10
nuxtApp . payload . isCached = Boolean ( useRequestEvent ( ) ?. context . cache )
11
- if ( nuxtApp . payload . serverRendered && ! nuxtApp . payload . prerenderedAt && ! nuxtApp . payload . isCached ) {
11
+ if ( nuxtApp . payload . serverRendered && ! nuxtApp . payload . prerenderedAt && ! nuxtApp . payload . isCached && ! nuxtApp . $config . disableAuthAutoLoad ) {
12
12
await useUserSession ( ) . fetch ( )
13
13
}
14
14
} ,
You can’t perform that action at this time.
0 commit comments