Skip to content

Commit

Permalink
fix: Abort SSR rendering on redirect (#438)
Browse files Browse the repository at this point in the history
Co-authored-by: Niels Janssen <[email protected]>
Co-authored-by: Zoey <[email protected]>
  • Loading branch information
3 people authored Sep 23, 2023
1 parent e2ea743 commit 6b9da1a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/runtime/utils/url.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { joinURL } from 'ufo'
import getURL from 'requrl'
import { sendRedirect } from 'h3'
import { useRequestEvent, useNuxtApp } from '#app'
import { useRequestEvent, useNuxtApp, abortNavigation } from '#app'
import { useAuthState, useRuntimeConfig } from '#imports'

export const getRequestURL = (includePath = true) => getURL(useRequestEvent()?.node.req, includePath)
Expand All @@ -24,7 +24,11 @@ export const navigateToAuthPages = (href: string) => {

if (process.server) {
if (nuxtApp.ssrContext && nuxtApp.ssrContext.event) {
return nuxtApp.callHook('app:redirected').then(() => sendRedirect(nuxtApp.ssrContext!.event, href, 302))
return nuxtApp.callHook('app:redirected').then(() => {
sendRedirect(nuxtApp.ssrContext!.event, href, 302)

abortNavigation()
})
}
}

Expand Down

0 comments on commit 6b9da1a

Please sign in to comment.