Skip to content

[BUG] ReactSDKClient setUser() is not working #236

@dtrenz

Description

@dtrenz

Is there an existing issue for this?

  • I have searched the existing issues

SDK Version

3.0.0

Current Behavior

When attempting to set the user ID on the Optimizely ReactSDK client using setUser() I see the following error when implementing a feature flag:

Unable to determine if feature "<feature key>" is enabled because User ID is not set 

Expected Behavior

Setting a user ID using setUser() should set the usr ID on the client.

Steps To Reproduce

import { createInstance, OptimizelyProvider } from "@optimizely/react-sdk"; const App = () => { const optimizelyClient = createInstance({ sdkKey: "<key>", }); optimizelyClient.setUser({ id: "12345" }); return ( <OptimizelyProvider optimizely={optimizelyClient}> <Children /> </OptimizelyProvider> ); }

...then, in a child component:

 const [isEnabled] = useFeature("<feature key>");

React Framework

React 18.2.0 (Create React App + react-app-rewired)

Browsers impacted

Reproducible in both Chrome and Safari. No other browsers were tested. The issue does not seem to be browser-specific.

Link

No response

Logs

Screenshot 2024-01-29 at 4 12 02 PM

Severity

No response

Workaround/Solution

I'm forced to abandon this approach and have to set the user ID via the user prop in <OptimizelyProvider>.

Recent Change

No

Conflicts

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions