Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Ru
Answered
Spectacled bear posted this in #help-forum
Spectacled bearOP
Getting error while building the application.
import { NextResponse } from 'next/server'
import { IncomingMessage } from 'http'
import { getSession } from 'next-auth/react'
import { NextRequest } from 'next/server'
import { IncomingMessage } from 'http'
export async function middleware(request: NextRequest) {
const requestUrl = new URL(request.url)
const searchParams = requestUrl.searchParams.toString()
const session = await getSession({ req: request as any as IncomingMessage })
const key = '3EK6FD+o0+c7tzBNVfjpMkNDi2yARAAKzQlk8O2IKoxQu4nF7EdAh8s3TwpHwrdWT6R'
const baseUrl='https://new-app.stenhouse.com'
const { pathname, origin } = request.nextUrl
// NEW UI CONDITION
if (pathname.includes('/new-app')) {
if (pathname.includes('/login')) return NextResponse.next()
if (!session) {
const loginUrl = new URL('/new-app/login', origin)
return NextResponse.redirect(loginUrl)
}
return NextResponse.next()
}
return NextResponse.redirect(
new URL(searchParams ?${baseUrl}?${searchParams}: baseUrl, request.url),
)
}
export const config = {
matcher: ['/(STEN.+)', '/new-app'],
}
Answered by joulev
Pretty sure next-auth v4’s getSession is not compatible with the edge runtime. Try using getToken instead (also a next-auth function).
next-auth v5 (beta) fully works in the edge runtime.
next-auth v5 (beta) fully works in the edge runtime.
5 Replies
Spectacled bearOP
anyone?
@Spectacled bear Getting error while building the application.
>
> import { NextResponse } from 'next/server'
>
> import { IncomingMessage } from 'http'
> import { getSession } from 'next-auth/react'
> import { NextRequest } from 'next/server'
> import { IncomingMessage } from 'http'
>
> export async function middleware(request: NextRequest) {
> const requestUrl = new URL(request.url)
> const searchParams = requestUrl.searchParams.toString()
> const session = await getSession({ req: request as any as IncomingMessage })
>
> const key = '3EK6FD+o0+c7tzBNVfjpMkNDi2yARAAKzQlk8O2IKoxQu4nF7EdAh8s3TwpHwrdWT6R'
>
> const baseUrl='https://new-app.stenhouse.com'
> const { pathname, origin } = request.nextUrl
> // NEW UI CONDITION
> if (pathname.includes('/new-app')) {
> if (pathname.includes('/login')) return NextResponse.next()
>
> if (!session) {
> const loginUrl = new URL('/new-app/login', origin)
> return NextResponse.redirect(loginUrl)
> }
> return NextResponse.next()
> }
>
> return NextResponse.redirect(
> new URL(searchParams ? `${baseUrl}?${searchParams}` : baseUrl, request.url),
> )
> }
>
> export const config = {
> matcher: ['/(STEN.+)', '/new-app'],
> }
Pretty sure next-auth v4’s getSession is not compatible with the edge runtime. Try using getToken instead (also a next-auth function).
next-auth v5 (beta) fully works in the edge runtime.
next-auth v5 (beta) fully works in the edge runtime.
Answer
Spectacled bearOP
Thanks, i'll try
@joulev Pretty sure next-auth v4’s getSession is not compatible with the edge runtime. Try using getToken instead (also a next-auth function).
next-auth v5 (beta) fully works in the edge runtime.
Spectacled bearOP
It worked but is it mentioned somewhere in docs? I want to read about it