fix redirect error
This commit is contained in:
@@ -5,13 +5,18 @@
|
|||||||
<div v-if="error" class="error">
|
<div v-if="error" class="error">
|
||||||
<h2>Debug Information</h2>
|
<h2>Debug Information</h2>
|
||||||
<p><strong>Error:</strong> {{ error }}</p>
|
<p><strong>Error:</strong> {{ error }}</p>
|
||||||
<p v-if="pageContext"><strong>PageContext keys:</strong> {{ pageContext.join(', ') }}</p>
|
<p v-if="pageContext">
|
||||||
|
<strong>PageContext keys:</strong> {{ pageContext.join(', ') }}
|
||||||
|
</p>
|
||||||
<pre v-if="urlParsed">{{ JSON.stringify(urlParsed, null, 2) }}</pre>
|
<pre v-if="urlParsed">{{ JSON.stringify(urlParsed, null, 2) }}</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else-if="redirectUrl">
|
<div v-else-if="redirectUrl">
|
||||||
<p>Redirecting to preview...</p>
|
<p>Redirecting to preview...</p>
|
||||||
<p>If you are not redirected automatically, <a :href="redirectUrl">click here</a>.</p>
|
<p>
|
||||||
|
If you are not redirected automatically,
|
||||||
|
<a :href="redirectUrl">click here</a>.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else>
|
<div v-else>
|
||||||
@@ -24,8 +29,7 @@
|
|||||||
import { useData } from 'vike-vue/useData'
|
import { useData } from 'vike-vue/useData'
|
||||||
import { onMounted } from 'vue'
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
const data = useData()
|
const { redirectUrl, error, pageContext, urlParsed } = useData()
|
||||||
const { redirectUrl, error, pageContext, urlParsed } = data
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (redirectUrl) {
|
if (redirectUrl) {
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ export const data = async (pageContext) => {
|
|||||||
const { urlParsed } = pageContext
|
const { urlParsed } = pageContext
|
||||||
const searchParams = urlParsed?.search || {}
|
const searchParams = urlParsed?.search || {}
|
||||||
|
|
||||||
console.log('Preview route - pageContext keys:', Object.keys(pageContext))
|
console.log(
|
||||||
|
'Preview route - pageContext keys:',
|
||||||
|
Object.keys(pageContext),
|
||||||
|
)
|
||||||
console.log('Preview route - urlParsed:', urlParsed)
|
console.log('Preview route - urlParsed:', urlParsed)
|
||||||
console.log('Preview route - searchParams:', searchParams)
|
console.log('Preview route - searchParams:', searchParams)
|
||||||
|
|
||||||
@@ -15,12 +18,17 @@ export const data = async (pageContext) => {
|
|||||||
path = '/',
|
path = '/',
|
||||||
status = 'draft',
|
status = 'draft',
|
||||||
documentId,
|
documentId,
|
||||||
uid
|
uid,
|
||||||
} = searchParams
|
} = searchParams
|
||||||
|
|
||||||
// Validate preview secret
|
// Validate preview secret
|
||||||
if (!secret || secret !== import.meta.env.VITE_PREVIEW_SECRET) {
|
if (!secret || secret !== import.meta.env.VITE_PREVIEW_SECRET) {
|
||||||
console.log('Invalid secret:', secret, 'Expected:', import.meta.env.VITE_PREVIEW_SECRET)
|
console.log(
|
||||||
|
'Invalid secret:',
|
||||||
|
secret,
|
||||||
|
'Expected:',
|
||||||
|
import.meta.env.VITE_PREVIEW_SECRET,
|
||||||
|
)
|
||||||
throw redirect('/preview-unauthorized')
|
throw redirect('/preview-unauthorized')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,10 +53,9 @@ export const data = async (pageContext) => {
|
|||||||
|
|
||||||
// Use Vike's redirect
|
// Use Vike's redirect
|
||||||
throw redirect(redirectUrl)
|
throw redirect(redirectUrl)
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If it's a redirect, let it pass through
|
// If it's a redirect, let it pass through
|
||||||
if (error.redirectTo) {
|
if (error._isAbortError) {
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +66,7 @@ export const data = async (pageContext) => {
|
|||||||
redirectUrl: null,
|
redirectUrl: null,
|
||||||
error: error.message || 'Failed to process preview request',
|
error: error.message || 'Failed to process preview request',
|
||||||
pageContext: Object.keys(pageContext),
|
pageContext: Object.keys(pageContext),
|
||||||
urlParsed: pageContext.urlParsed
|
urlParsed: pageContext.urlParsed,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user