Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
zoey-kaiser authored Sep 23, 2023
2 parents beb621a + 55aee8a commit 0cdbc0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sidebase/nuxt-auth",
"version": "0.6.0-beta.4",
"version": "0.6.0-beta.5",
"license": "MIT",
"type": "module",
"exports": {
Expand Down
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 0cdbc0d

Please sign in to comment.