anonymize

Dissociate the current session from the identified user.

This method dissociates the current session from the identified user, serving as the equivalent of the anonymize method available on the client side.

You should call this method when a user logs out to start a new anonymous session.

Signature

This function has the following signature:

function anonymize(route?: RouteContext): Promise<void>

Example

Here is an example of how to use this function:

Server action example
123456789101112131415
'use client';
import {logout} from '@/app/services';
import {anonymizeUser} from '@/app/actions';
export function LogoutButton() {
const onClick = async () => {
// Your logout logic
await logout();
// Anonymize the user
await anonymizeUser();
};
return (<button onClick={onClick}>Logout</button>);
}

Parameters

The following list describes the supported parameters:

route(optional)
object

The context of the current route.

The property names are aligned with those in Next.js for easy forwarding, as shown in the Page router example.

req
NextApiRequest|NextRequest|GetServerSidePropsRequest

The request object.

res
NextApiResponse|NextResponse|GetServerSidePropsResponse

The response object.