Skip to content

Commit

Permalink
Allow null userid on setUser
Browse files Browse the repository at this point in the history
  • Loading branch information
rafinutshaw-optimizely committed Jul 21, 2023
1 parent 026aef0 commit b325837
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,22 +348,18 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
}

public async setUser(userInfo: UserInfo): Promise<void> {
this.isUserReady = false;
this.isUserPromiseResolved = false;
this.isUserReady = true;

// TODO add check for valid user
if (userInfo.id) {
this.user.id = userInfo.id;
this.isUserReady = true;
this.user.id = userInfo.id;

if (this._client) {
this.userContext = this._client.createUserContext(userInfo.id, userInfo.attributes);
} else {
logger.warn(
'Unable to create user context for user id "%s" because Optimizely client failed to initialize.',
this.user.id
);
}
if (this._client) {
this.userContext = this._client.createUserContext(userInfo.id ?? undefined, userInfo.attributes);
} else {
logger.warn(
'Unable to create user context for user id "%s" because Optimizely client failed to initialize.',
this.user.id
);
}

if (userInfo.attributes) {
Expand Down

0 comments on commit b325837

Please sign in to comment.