nextauth middleware error
Unanswered
DhrishP1 posted this in #help-forum
DhrishP1OP
import { NextRequest, NextResponse } from 'next/server'
export { auth as middlewarefun } from '@/auth'
export async function middleware(req: NextRequest) {
const { pathname } = req.nextUrl
if (pathname.length === 10) { //for '/parameter'
return NextResponse.redirect(process.env.NEXT_PUBLIC_BASE_URL as string)
}
if (
pathname.includes('parameter')
) {
const res = await fetch(
`${process.env.NEXT_PUBLIC_BASE_URL}/api/getparamquery`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ path: pathname })
}
)
const resText = await res.text()
if (resText.length > 0) {
return NextResponse.redirect(
`${process.env.NEXT_PUBLIC_BASE_URL}?prequery=${resText}`
)
}
return NextResponse.next()
}
return NextResponse.next()
}
export const config = {
matcher: '/(.*)'
}exporting auth as middlewarefun is giving error in production
error in console:https://authjs.dev/reference/core/errors#invalidcheck
please tell how can I export auth as middleware or use auth inside my middleware function to see the token