anonymize

Learn how to anonymize the current visitor on the server.

This function anonymizes the current visitor by re-issuing an anonymous user token.

Call it from a server action with the action’s load context, typically from your logout flow. The updated token is persisted when the response cookies are written.

Signature

This function has the following signature:

function anonymize(scope: CroctContext): Promise<void>;

Example

Anonymize the visitor in a logout action:

app/routes/logout.tsx
import {redirect} from 'react-router';import {anonymize} from '@croct/plug-hydrogen/server';import type {Route} from './+types/logout';
export async function action({context}: Route.ActionArgs) {  await anonymize(context);
  return redirect('/');}

Parameters

The following list describes the supported parameters:

scope
CroctContext

The Hydrogen load context for the current request.