Skip to content

Commit fa54b5d

Browse files
committed
chore: Remove console logging
1 parent 88fb653 commit fa54b5d

File tree

2 files changed

+72
-39
lines changed

2 files changed

+72
-39
lines changed

src/components/LoggedIn.svelte

Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
RecordModel,
2121
} from "pocketbase";
2222
import { customFetch } from "src/customFetch";
23+
import { curryLog } from "src/debug";
2324
import { FeatureFlagManager, flags } from "src/flagManager";
2425
2526
export let plugin: Live;
2627
28+
let errorLog = curryLog("LoggedIn.svelte", "error");
29+
2730
let lm: LoginManager;
2831
let automaticFlow = writable<boolean>(!Platform.isIosApp);
2932
let pending = writable<boolean>(false);
@@ -37,29 +40,29 @@
3740
let providers: Record<string, Provider> = {};
3841
let hasProviderInfo = writable<boolean>(false);
3942
const loginSettings = lm.loginSettings;
40-
43+
4144
// Load cached providers from localStorage, keyed by auth URL
4245
let cachedProviders = writable<string[]>([]);
4346
let shouldAnimate = writable<boolean>(false);
44-
const PROVIDERS_CACHE_PREFIX = 'system3-relay-auth-providers-';
45-
47+
const PROVIDERS_CACHE_PREFIX = "system3-relay-auth-providers-";
48+
4649
function getCacheKey(): string {
4750
// Use the PocketBase URL as the cache key
48-
const pbUrl = lm.pb?.baseUrl || 'default';
51+
const pbUrl = lm.pb?.baseUrl || "default";
4952
return `${PROVIDERS_CACHE_PREFIX}${pbUrl}`;
5053
}
51-
54+
5255
function getDefaultProviders(): string[] {
5356
const defaults = ["google", "microsoft"];
54-
57+
5558
if ($flagManager.getFlag("enableDiscordLogin")) {
5659
defaults.push("discord");
5760
}
5861
if ($flagManager.getFlag("enableGitHubLogin")) {
5962
defaults.push("github");
6063
}
6164
// OIDC is intentionally excluded from defaults
62-
65+
6366
return defaults;
6467
}
6568
@@ -71,18 +74,18 @@
7174
return JSON.parse(cached);
7275
}
7376
} catch (e) {
74-
console.error("Failed to load cached providers:", e);
77+
errorLog("Failed to load cached providers:", e);
7578
}
7679
// Return default providers if no cache exists
7780
return getDefaultProviders();
7881
}
79-
82+
8083
function saveCachedProviders(providerList: string[]) {
8184
try {
8285
const cacheKey = getCacheKey();
8386
localStorage.setItem(cacheKey, JSON.stringify(providerList));
8487
} catch (e) {
85-
console.error("Failed to save cached providers:", e);
88+
errorLog("Failed to save cached providers:", e);
8689
}
8790
}
8891
@@ -104,57 +107,74 @@
104107
});
105108
106109
const visibleProviders = derived(
107-
[selectedProvider, lm.loginSettings, flagManager, hasProviderInfo, cachedProviders],
110+
[
111+
selectedProvider,
112+
lm.loginSettings,
113+
flagManager,
114+
hasProviderInfo,
115+
cachedProviders,
116+
],
108117
() => {
109118
// First check the loginSettings store
110119
if ($loginSettings && $loginSettings.provider)
111120
return [$loginSettings.provider];
112121
113122
// Fall back to selectedProvider for compatibility
114123
if ($selectedProvider !== "") return [$selectedProvider];
115-
124+
116125
// If we have provider info from the API, only show those that are available
117126
if ($hasProviderInfo && Object.keys(providers).length > 0) {
118127
// Filter to only show providers that were returned from the API
119128
const availableFromApi = Object.keys(providers);
120129
const visible = [];
121-
130+
122131
// Check each provider in preferred order
123132
if (availableFromApi.includes("google")) {
124133
visible.push("google");
125134
}
126135
if (availableFromApi.includes("microsoft")) {
127136
visible.push("microsoft");
128137
}
129-
if (availableFromApi.includes("discord") && $flagManager.getFlag("enableDiscordLogin")) {
138+
if (
139+
availableFromApi.includes("discord") &&
140+
$flagManager.getFlag("enableDiscordLogin")
141+
) {
130142
visible.push("discord");
131143
}
132-
if (availableFromApi.includes("github") && $flagManager.getFlag("enableGitHubLogin")) {
144+
if (
145+
availableFromApi.includes("github") &&
146+
$flagManager.getFlag("enableGitHubLogin")
147+
) {
133148
visible.push("github");
134149
}
135-
150+
136151
// Include any OIDC providers (oidc, oidc2, oidc-custom, etc.) if feature flag is enabled
137-
availableFromApi.forEach(provider => {
138-
if (provider.startsWith("oidc") && $flagManager.getFlag("enableOIDCLogin")) {
152+
availableFromApi.forEach((provider) => {
153+
if (
154+
provider.startsWith("oidc") &&
155+
$flagManager.getFlag("enableOIDCLogin")
156+
) {
139157
visible.push(provider);
140158
}
141159
});
142-
160+
143161
// Check if the list has changed from what we expected (cached or defaults)
144-
const hasChanged = JSON.stringify(visible.sort()) !== JSON.stringify($cachedProviders.sort());
162+
const hasChanged =
163+
JSON.stringify(visible.sort()) !==
164+
JSON.stringify($cachedProviders.sort());
145165
shouldAnimate.set(hasChanged);
146-
166+
147167
// Save to cache for next time
148168
saveCachedProviders(visible);
149-
169+
150170
return visible;
151171
}
152-
172+
153173
// If we have cached providers and no API info yet, use the cache
154174
if ($cachedProviders.length > 0 && !$hasProviderInfo) {
155175
return $cachedProviders;
156176
}
157-
177+
158178
// Default behavior if no provider info yet or request failed
159179
const visible = ["google", "microsoft"];
160180
@@ -188,7 +208,7 @@
188208
const names: Record<string, string> = {};
189209
for (const providerName of Object.keys(providers)) {
190210
const provider = providers[providerName];
191-
211+
192212
if (provider?.info?.displayName) {
193213
names[providerName] = provider.info.displayName;
194214
} else {
@@ -298,11 +318,10 @@
298318
299319
function capitalize(s: string): string {
300320
if (!s) return "";
301-
if (s == "oidc") return "OIDC";
302-
if (s == "github") return "GitHub";
321+
if (s == "oidc") return "OIDC";
322+
if (s == "github") return "GitHub";
303323
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
304324
}
305-
306325
</script>
307326

308327
{#if $lm.hasUser && $lm.user}
@@ -326,13 +345,18 @@
326345
<div class="login-buttons">
327346
{#each $visibleProviders as provider (provider)}
328347
<button
329-
class={`${provider.startsWith('oidc') ? 'oidc' : provider}-sign-in-button`}
348+
class={`${provider.startsWith("oidc") ? "oidc" : provider}-sign-in-button`}
330349
disabled={$pending || !$configuredProviders.contains(provider)}
331-
transition:slide={{ duration: $shouldAnimate ? 300 : 0, easing: quintOut }}
350+
transition:slide={{
351+
duration: $shouldAnimate ? 300 : 0,
352+
easing: quintOut,
353+
}}
332354
on:click={debounce(async () => {
333355
pending.set(true);
334356
await login(provider);
335-
})}>Sign in with {$providerDisplayNames[provider] || capitalize(provider)}</button
357+
})}
358+
>Sign in with {$providerDisplayNames[provider] ||
359+
capitalize(provider)}</button
336360
>
337361
{/each}
338362
</div>
@@ -342,21 +366,30 @@
342366
{#if providers[provider]}
343367
<a href={providers[provider].fullAuthUrl} target="_blank">
344368
<button
345-
class={`${provider.startsWith('oidc') ? 'oidc' : provider}-sign-in-button`}
369+
class={`${provider.startsWith("oidc") ? "oidc" : provider}-sign-in-button`}
346370
disabled={$pending || !providers[provider]}
347-
transition:slide={{ duration: $shouldAnimate ? 300 : 0, easing: quintOut }}
371+
transition:slide={{
372+
duration: $shouldAnimate ? 300 : 0,
373+
easing: quintOut,
374+
}}
348375
on:click={() => {
349376
pending.set(true);
350377
poll(provider);
351-
}}>Sign in with {$providerDisplayNames[provider] || capitalize(provider)}</button
378+
}}
379+
>Sign in with {$providerDisplayNames[provider] ||
380+
capitalize(provider)}</button
352381
>
353382
</a>
354383
{:else}
355-
<button
356-
class={`${provider.startsWith('oidc') ? 'oidc' : provider}-sign-in-button`}
384+
<button
385+
class={`${provider.startsWith("oidc") ? "oidc" : provider}-sign-in-button`}
357386
disabled={true}
358-
transition:slide={{ duration: $shouldAnimate ? 300 : 0, easing: quintOut }}
359-
>Sign in with {$providerDisplayNames[provider] || capitalize(provider)}</button
387+
transition:slide={{
388+
duration: $shouldAnimate ? 300 : 0,
389+
easing: quintOut,
390+
}}
391+
>Sign in with {$providerDisplayNames[provider] ||
392+
capitalize(provider)}</button
360393
>
361394
{/if}
362395
{/each}

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export default class Live extends Plugin {
203203
}));
204204
new Notice("✓ Endpoints validated and applied successfully!", 5000);
205205
if (result.licenseInfo) {
206-
console.log("License validation successful:", result.licenseInfo);
206+
this.log("License validation successful:", result.licenseInfo);
207207
}
208208
} else {
209209
// Store validation error for display in settings

0 commit comments

Comments
 (0)