🐛 Fix the auth middleware
This commit is contained in:
@@ -5,7 +5,17 @@ export default defineNuxtPlugin(() => {
|
||||
console.log(`[AUTH PLUGIN] Running on ${side}`)
|
||||
const userStore = useUserStore()
|
||||
|
||||
// Prevent fetching if it's already in progress
|
||||
// Fix hydration mismatch: if isLoading is true on client, it's likely a stale state
|
||||
// from SSR where the fetch didn't complete before the response was sent.
|
||||
// Reset it to allow the client to fetch properly.
|
||||
if (import.meta.client && userStore.isLoading) {
|
||||
console.log(
|
||||
`[AUTH PLUGIN] Detected stale isLoading state on ${side}. Resetting to allow fetch.`
|
||||
)
|
||||
userStore.isLoading = false
|
||||
}
|
||||
|
||||
// Prevent fetching if it's already in progress (server-side only now)
|
||||
if (userStore.isLoading) {
|
||||
console.log(
|
||||
`[AUTH PLUGIN] User fetch already in progress on ${side}. Skipping.`
|
||||
@@ -21,4 +31,3 @@ export default defineNuxtPlugin(() => {
|
||||
userStore.fetchUser()
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user