Next.js Auth0: Resetting Login Flow After Consent Decline

I have a login form added using nextjs-auth0 v3. Here is my auth/[auth0]/route.js

import { handleAuth, handleCallback, handleLogin } from "@auth0/nextjs-auth0";
import { NextResponse } from "next/server";

const handleCallbackWithErrors = async (req, res) => {
  try {
    return await handleCallback(req, res);
  } catch (error) {
    console.error("Authentication Callback Error:", error);
    // Redirect to /api/auth/callback with error query param for user decline
    const redirectUrl = new URL(process.env.AUTH0_BASE_URL);
    return NextResponse.redirect("redirectUrl");
  }
};

export const GET = handleAuth({
  callback: handleCallbackWithErrors,
  signup: handleLogin({ authorizationParams: { prompt: "login", screen_hint: "signup" } }),
});

When user clicks clicks on login they reach the auth0 login/signup page and upon filling signup form they are taken to consent form. On agreeing consent the auth flow completes.

I face an issue when user declines consent form and tries to login with a different email id. On that browser, if they try to go to access login/signup form again, they are automatically taken to consent form with previous identity. As a developer I clear cookies in .auth0.com to get access to signup form again.

How can I use nextjs-auth0 to do this? I have a feeling I am overlooking something simple here, but I am just unable to get it to work after many trials.

Any help is much appreciated! :raised_hands:t3:

Hi @prashanthgandhiraj

Welcome to the Auth0 Community!

I would recommend you to read our documentation about Sessions. I believe you are not clearing the session inside the browser and the cookies for the consent form are still pointing to the old user.

If you have any other questions, feel free to leave a reply!

Kind Regards,
Nik