Next.js Discord

Discord Forum

Too many redirects from localhost

Unanswered
Atlantic mackerel posted this in #help-forum
Open in Discord
Atlantic mackerelOP
Hey guys, im trying to add auth and when user login, then redirect to the other url like http://localhost:3000/clinet/uuid but I don't know exact reason the error Too many redirects from localhost. (I guess it's just infinite looping from middleware.ts)

And below is my middleware.ts code

import {withAuth} from "next-auth/middleware"
import {NextResponse} from "next/server";

export default withAuth(
    function middleware(req) {

        if (req.nextauth.token) {
            return NextResponse.redirect(
                new URL(
                    `/client/test`,
                    req.url
                ));
        }
    }
)

and also I edit my next.config.mjs but it won't work


/** @type {import('next').NextConfig} */
const nextConfig = {
    matcher: [
        '/',
        '/login',
        '/client/'
    ]
};

export default nextConfig;


how can I fix this problem?

And I wonder how to matcher like this url http://localhost:3000/[uuid]

0 Replies