Skip to content

Commit

Permalink
fix: Don't fetch session during nitro prerender (#521)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Thiessen <[email protected]>
Co-authored-by: Zoey <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2023
1 parent 7234c66 commit 972b561
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/runtime/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { addRouteMiddleware, defineNuxtPlugin, useRuntimeConfig } from '#app'
import { getHeader } from 'h3'
import authMiddleware from './middleware/auth'
import { useAuth, useAuthState } from '#imports'

Expand All @@ -7,8 +8,14 @@ export default defineNuxtPlugin(async (nuxtApp) => {
const { data, lastRefreshedAt } = useAuthState()
const { getSession } = useAuth()

// Skip auth if we're prerendering
let nitroPrerender = false
if (nuxtApp.ssrContext) {
nitroPrerender = getHeader(nuxtApp.ssrContext.event, 'x-nitro-prerender') !== undefined
}

// Only fetch session if it was not yet initialized server-side
if (typeof data.value === 'undefined') {
if (typeof data.value === 'undefined' && !nitroPrerender) {
await getSession()
}

Expand Down

0 comments on commit 972b561

Please sign in to comment.