# posthog feature flag call failed without distinct id

## TL;DR
Feature flags evaluate per user, so calling for a flag before identify leaves PostHog nothing to evaluate against. Move flag evaluation to after identify, or pass the distinct ID explicitly in server-side calls. Confirm flags resolve in PostHog's flag debugger, and gate evaluation so it can never run pre-identify.

```text
posthog feature flag call failed without distinct id
```

## Use this when

- PostHog flag calls fail or return defaults before login
- Flags work for logged-in users but not anonymous ones
- Server-side flag evaluation errors mentioning identity

## Not for this skill when

- Flags misconfigured in the PostHog dashboard (rules, rollout percentages)
- Invalid PostHog API key errors
- Flags not updating after a dashboard change (caching)

## Steps

### Step 1: Find the premature flag call

Locate the flag evaluation call and check its position relative to identify in the code. Expected: you confirm the flag runs before any identity exists.

### Step 2: Move evaluation after identify

Reorder so identify completes first, then evaluate flags. Expected: the flag call now has an identity to evaluate against.

### Step 3: Pass IDs explicitly server-side

In server-side code, pass the distinct ID directly to the flag evaluation call. Expected: server evaluations resolve correctly.

### Step 4: Handle anonymous users

Ensure the SDK has generated an anonymous distinct ID before evaluating flags for logged-out users. Expected: anonymous flag evaluation works.

### Step 5: Verify in the debugger

Use PostHog's feature flag debugger to confirm evaluation for a test identity. Expected: the flag returns the expected variant.

### Step 6: Add an evaluation gate

Wrap flag calls so they no-op or wait until identity is ready. Expected: the ordering bug cannot recur.

## Tool compatibility

PostHog JavaScript and server SDKs; PostHog feature flags; identify and distinct ID semantics.

## Variant phrasings

### Variant 1

posthog getfeatureflag failed no distinct id

### Variant 2

posthog feature flag before identify error

### Variant 3

posthog isfeatureenabled without user id

## Why it happens

PostHog evaluates feature flags against a specific user identity, applying targeting rules, cohorts, and rollout percentages to that identity. Without a distinct ID there is no one to evaluate, so the call fails or falls back to a default that may be wrong. The bug is a sequencing problem in application code: flag-gated UI renders before the authentication or anonymous-ID setup completes. It is especially common in server-side rendering, where the server has no identity at all, and in single-page apps that evaluate flags at module load. Gating evaluation on identity readiness fixes the whole class, not just one call site.

## Edge cases / pitfalls

- SSR flag evaluation needs the distinct ID passed from the client; the server cannot invent one.
- Bootstrap flags can provide initial values before the SDK loads; use them for above-the-fold gating.
- Changing a user's ID without re-evaluating flags leaves stale variants; re-evaluate after identify.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_sVxkDz9UAaRFQBnfbNj0SQ
