Hi @teodor.andrei, I use it in the middleware. Here’s the code snippet
export default async function middleware(req: NextRequest) {
…
import { getSession } from ‘@auth0/nextjs-auth0/edge’;
const session = await getSession();
if (!session) {
const loginUrl = new URL('/api/auth/login', req.url);
loginUrl.searchParams.set('returnTo', req.url);
return NextResponse.redirect(loginUrl);
}
…
The users get stuck in a loop, where from middleware they and redirected to /login page and when they return using returnTo url, they are again redirected to /login page even after successful login