Skip to content

Commit a7c294e

Browse files
lukythHazAT
authored andcommitted
fix: Update user type in scope.setUser for unset case (getsentry#1998)
According to getsentry/sentry-docs#500 (comment), we should be able to unset a user in global scope by setting a user to `null`.
1 parent 2ce4745 commit a7c294e

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

packages/hub/src/scope.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class Scope implements ScopeInterface {
9696
/**
9797
* @inheritDoc
9898
*/
99-
public setUser(user: User): this {
99+
public setUser(user: User | null): this {
100100
this._user = normalize(user);
101101
this._notifyScopeListeners();
102102
return this;

packages/hub/test/scope.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ describe('Scope', () => {
5757
scope.setUser({ id: '1' });
5858
expect((scope as any)._user).toEqual({ id: '1' });
5959
});
60+
test('unset', () => {
61+
const scope = new Scope();
62+
scope.setUser(null);
63+
expect((scope as any)._user).toEqual(null);
64+
});
6065
});
6166

6267
describe('level', () => {

packages/types/src/scope.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export interface Scope {
1414
/**
1515
* Updates user context information for future events.
1616
*
17-
* @param user User context object to be set in the current context.
17+
* @param user User context object to be set in the current context. Pass `null` to unset the user.
1818
*/
19-
setUser(user: User): this;
19+
setUser(user: User | null): this;
2020

2121
/**
2222
* Set an object that will be merged sent as tags data with the event.

0 commit comments

Comments
 (0)