MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / getOrCreateAnonymousId

Function getOrCreateAnonymousId

packages/web/src/lib/anonymousId.ts:11–29  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9 * This is used to track ownership of chats created by anonymous (non-authenticated) users.
10 */
11export const getOrCreateAnonymousId = async (): Promise<string> => {
12 const cookieStore = await cookies();
13 const existingId = cookieStore.get(ANONYMOUS_ID_COOKIE_NAME)?.value;
14
15 if (existingId) {
16 return existingId;
17 }
18
19 const newId = uuidv4();
20 cookieStore.set(ANONYMOUS_ID_COOKIE_NAME, newId, {
21 httpOnly: true,
22 secure: process.env.NODE_ENV === 'production',
23 sameSite: 'lax',
24 maxAge: COOKIE_MAX_AGE,
25 path: '/',
26 });
27
28 return newId;
29};
30
31/**
32 * Gets the anonymous session ID from the cookie if it exists.

Callers 2

createChatFunction · 0.90
duplicateChatFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected