Skip to content

Commit e8527fc

Browse files
committed
Disable client when project token is missing
1 parent e35bf94 commit e8527fc

3 files changed

Lines changed: 338 additions & 39 deletions

File tree

src/PostHog/Config/PostHogOptions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Extensions.Options;
2+
using PostHog.Library;
23

34
namespace PostHog;
45

@@ -26,6 +27,15 @@ public string? ProjectToken
2627

2728
internal bool HasLegacyProjectApiKey => _projectApiKey is not null;
2829

30+
internal void Normalize()
31+
{
32+
_projectToken = _projectToken.NullIfEmpty();
33+
_projectApiKey = _projectApiKey.NullIfEmpty();
34+
PersonalApiKey = PersonalApiKey.NullIfEmpty();
35+
HostUrl = HostUrl.NormalizeHostUrl();
36+
Disabled = Disabled || ProjectToken is null;
37+
}
38+
2939
/// <summary>
3040
/// Obsolete alias for <see cref="ProjectToken"/>.
3141
/// </summary>
@@ -49,6 +59,11 @@ public string? ProjectApiKey
4959
/// </remarks>
5060
public string? PersonalApiKey { get; set; }
5161

62+
/// <summary>
63+
/// Whether this client is disabled and should no-op instead of sending data to PostHog. (Default: false)
64+
/// </summary>
65+
public bool Disabled { get; set; }
66+
5267
/// <summary>
5368
/// PostHog API host, usually 'https://us.i.posthog.com' (default) or 'https://eu.i.posthog.com'
5469
/// </summary>

0 commit comments

Comments
 (0)