Optional
state: { Validate additional claims
// app/api/auth/[auth0]/route.js
import { handleAuth, handleCallback } from '@auth0/nextjs-auth0';
import { redirect } from 'next/navigation';
const afterCallback = (req, session, state) => {
if (session.user.isAdmin) {
return session;
} else {
redirect('/unauthorized');
}
};
export default handleAuth({
callback: handleCallback({ afterCallback })
});
Modify the session after login
// pages/api/auth/[auth0].js
import { handleAuth, handleCallback } from '@auth0/nextjs-auth0';
import { NextResponse } from 'next/server';
const afterCallback = (req, session, state) => {
session.user.customProperty = 'foo';
delete session.refreshToken;
return session;
};
export default handleAuth({
callback: handleCallback({ afterCallback })
});
Redirect successful login based on claim
// pages/api/auth/[auth0].js
import { handleAuth, handleCallback } from '@auth0/nextjs-auth0';
import { headers } from 'next/headers';
const afterCallback = (req, session, state) => {
if (!session.user.isAdmin) {
headers.set('location', '/admin');
}
return session;
};
export default handleAuth({
callback: handleCallback({ afterCallback })
});
HandlerError
Use this function for validating additional claims on the user's ID token or adding removing items from the session after login.