Skip to content

fix: clear traits when identifying over previous identity #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions flagsmith-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,10 @@ const Flagsmith = class {
}

identify(userId: string, traits?: ITraits) {
if(this.identity && this.identity !== userId) {
// clear out old traits when switching identity
this.withTraits = {}
}
this.identity = userId;
this.log("Identify: " + this.identity)

Expand Down
2 changes: 1 addition & 1 deletion lib/flagsmith-es/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flagsmith-es",
"version": "4.0.1",
"version": "4.0.2",
"description": "Feature flagging to support continuous development. This is an esm equivalent of the standard flagsmith npm module.",
"main": "./index.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion lib/flagsmith/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flagsmith",
"version": "4.0.1",
"version": "4.0.2",
"description": "Feature flagging to support continuous development",
"main": "./index.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion lib/react-native-flagsmith/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-flagsmith",
"version": "4.0.1",
"version": "4.0.2",
"description": "Feature flagging to support continuous development",
"main": "./index.js",
"repository": {
Expand Down
15 changes: 15 additions & 0 deletions test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,19 @@ describe('Flagsmith.init', () => {
const {flagsmith,initConfig} = getFlagsmith({onChange, environmentID:"bad"})
await expect(flagsmith.init(initConfig)).rejects.toThrow(Error);
});
test('identifying with new identity should not carry over previous traits for different identity', async () => {
const onChange = jest.fn()
const now = Date.now();
const identityA = `test_identity_a_${now}`
const identityB = `test_identity_b_${now}`
const {flagsmith,initConfig} = getFlagsmith({onChange, identity:identityA, traits: {a:`example`}})
await flagsmith.init(initConfig);
expect(flagsmith.getTrait("a")).toEqual(`example`)
await flagsmith.identify(identityB)
expect(flagsmith.getTrait("a")).toEqual(undefined)
await flagsmith.identify(identityA)
expect(flagsmith.getTrait("a")).toEqual(`example`)
await flagsmith.identify(identityB)
expect(flagsmith.getTrait("a")).toEqual(undefined)
});
});