When I press the decline button into this screen it redirect to error page (api/auth/callback?error=access_denied&error_description=User%20did%20not%20authorize%20the%20request)
I don’t have a callback url file in to the system. So how do I handle this?
Authorize app form:
error page after clicking on decline button:
any updates on this? I have the same problem
i’m using next “14.1.3” and @auth0/nextjs-auth0 “3.5.0”
I found the solution
add the following to your api/auth/[auth0]/route.ts
import { handleAuth, handleCallback, handleLogin } from '@auth0/nextjs-auth0';
import type { NextApiRequest, NextApiResponse } from 'next';
import { NextResponse } from 'next/server';
const callbackHandler = async (req: NextApiRequest, res: NextApiResponse) => {
try {
return await handleCallback(req, res, {
// Homepage
redirectUri: `${process.env.AUTH0_BASE_URL}`,
});
} catch (error) {
return { error, isError: true };
}
};
const authOptions = {
async callback(req: NextApiRequest, res: NextApiResponse) {
const response: any = await callbackHandler(req, res);
if (response.isError)
// You can replace the below path with your error path
return NextResponse.redirect(`${process.env.AUTH0_BASE_URL}`);
return response;
},
};
export const GET = handleAuth(authOptions);
There might be a better way to handle the decline, I guess leveraging the error and error message passed in the callback might be a better idea, however that’s the way I handled it using nextjs v14 app router