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
App router
JavaScript
123456789101112131415
'use client';import {logout} from '@/app/services';import {anonymizeUser} from '@/app/actions';export function LogoutButton() {const onClick = async () => {// Your logout logicawait logout();// Anonymize the userawait anonymizeUser();};return (<button onClick={onClick}>Logout</button>);}
Parameters
The following list describes the supported parameters:
- route(optional)object
The context of the current route.
Conditional requirementThis option is only needed for Page router or API routes, as the current request scope is only accessible through the App router and Server actions.
The property names are aligned with those in Next.js for easy forwarding, as shown in the Page router example.