Getting redirected from callback to authorization and back to callback in Next.js application

I am trying to create a next js application… but everytime I login it says redirected too many times. In network tab of chrome developer tools I can see that my application is redirecting from website callback url to Auth0 authorization then back to callback url and so on.

I have followed the docs and set my callback url in Auth0 Application Dashboard to http://localhost:3000/api/auth/callback
Logout Urls to

But still the issue persists-
This is my next js file code for […auth0].js

import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';

export default handleAuth({
  async callback(req, res) {
    try {
      await handleLogin(req, res, {
        authorizationParams: {
          scope: process.env.NEXT_PUBLIC_AUTH0_SCOPES,
    } catch (error) {
      res.status(error.status || 500).end(error.message);