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

Function getPostHogCookie

packages/web/src/lib/posthog.ts:29–51  ·  view source on GitHub ↗
(cookieStore: Pick<RequestCookies, 'get'>)

Source from the content-addressed store, hash-verified

27* undefined if the cookie is not found or is invalid.
28*/
29const getPostHogCookie = (cookieStore: Pick<RequestCookies, 'get'>): PostHogCookie | undefined => {
30 const phCookieKey = `ph_${env.POSTHOG_PAPIK}_posthog`;
31 const cookie = cookieStore.get(phCookieKey);
32
33 if (!cookie) {
34 return undefined;
35 }
36
37 const parsedCookie = (() => {
38 try {
39 return JSON.parse(cookie.value);
40 } catch (e) {
41 Sentry.captureException(e);
42 return null;
43 }
44 })();
45
46 if (isPostHogCookie(parsedCookie)) {
47 return parsedCookie;
48 }
49
50 return undefined;
51}
52
53/**
54 * Attempts to retrieve the distinct id of the current user.

Callers 1

tryGetPostHogDistinctIdFunction · 0.85

Calls 1

isPostHogCookieFunction · 0.85

Tested by

no test coverage detected