Skip to content

LDClient Doesn't Properly Identify User If Additional Data Isn't Passed #141

@StephenMP

Description

@StephenMP

When initializing the LDClient, if you use an LDUser without additional data other than key, the user is not properly identified. For example, let's say in the LD system, I have the following user:

{
    key: "abcd-1234",
    email: "fake@email.com"
}

Now, let's say I have the segment Cool Users. I have a rule that states that anyone with an email ending with @email.com is in this segment.

I also have a feature flagcool-users that will return true if the user is in the segment Cool Users. Then, in my typescript, I have the following code:

let ldUser: LDUser = {
    key: 'abcd-1234'
};

this.ldClient = initialize(MY_KEY, ldUser);
this.ldClient.on('ready', () => this.flags = this.ldClient.allFlags());

In the above example, the 'cool-users' feature flag is false.

However, if I modify the typescript to be (notice I added email):

let ldUser: LDUser = {
    key: 'abcd-1234',
    email: 'fake@email.com'
};

this.ldClient = initialize(MY_KEY, ldUser);
this.ldClient.on('ready', () => this.flags = this.ldClient.allFlags());

Then the 'cool-users' feature flag is true like it should be.

Do note that the client DOES identify the user in the LD system and update the user's metadata properly (e.g. if I were to add some custom data, it adds it to the user properly in the LD system); however, it appears it does not fully identify the user properly within the LDClient. In other words, I would expect the client to query the LD system and ask for a user with the given key. If the user exists, it would populate the client's current user with all existing data on that user in the LD system which would include the email address. Then, when I call something like this.ldClient.variation('cool-users') or when the client initializes it would return true for my user since their email ends with @email.com.

So, in my example, if I were to do the following:

let ldUser: LDUser = {
    key: 'abcd-1234'
};

this.ldClient = initialize(MY_KEY, ldUser);
this.ldClient.on('ready', () => this.flags = this.ldClient.allFlags());

I would expect the user that exists within the LDClient to be:

{
    key: "abcd-1234",
    email: "fake@email.com"
}

but it is not. The user that exists within the LDClient is:

{
    key: "abcd-1234"
}

NOTE
I'm not 100% sure this is an issue with the client or with the LD system. In other words, I'm not sure if the LD system isn't properly checking the user information when a call to get the feature flag values is made (i.e. if I pass a user with a key, does the LD system grab the user based on key, then evaluate the user's data, like email, against the rules in place for user segments or does the LD system just take the user provided to the call as is?).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions