Improved how auth tokens are synced to accounts

This commit is contained in:
WardPearce
2026-03-08 23:09:51 +13:00
parent c7e95a7b67
commit fa3965f7be
3 changed files with 17 additions and 9 deletions
+11
View File
@@ -15,6 +15,7 @@ import { isOwnBackend } from './shared';
import { Browser } from '@capacitor/browser';
import { clearFeedYTjs } from './api/youtubejs/subscriptions';
import { ensureNoTrailingSlash, isYTBackend } from './misc';
import { deleteKeyValue } from './api/backend/keyvalue';
export function clearCaches() {
feedCacheStore.set({});
@@ -29,6 +30,12 @@ export function authProtected() {
}
}
async function removeAuthFromBackend() {
if (!get(rawMasterKeyStore)) return;
await deleteKeyValue('authToken');
}
export async function setInvidiousInstance(
instanceUrl: string | undefined | null
): Promise<boolean> {
@@ -64,6 +71,8 @@ export async function setInvidiousInstance(
invidiousInstanceStore.set(instance);
invidiousAuthStore.set(null);
await removeAuthFromBackend();
return true;
}
@@ -86,6 +95,8 @@ export async function goToInvidiousLogin() {
export async function invidiousLogout() {
invidiousAuthStore.set(null);
await removeAuthFromBackend();
goto(resolve('/', {}));
}
@@ -9,22 +9,19 @@ import { addOrUpdateKeyValue, getKeyValue } from '$lib/api/backend/keyvalue';
import { rawMasterKeyStore } from '$lib/store';
import { getPublicEnv } from '$lib/misc';
const allowNullOverwrite = ['authToken'];
const dontAutoSync = ['authToken'];
export async function syncSettingsToBackend() {
if (!isOwnBackend() || !get(rawMasterKeyStore)) return;
await Promise.all(
persistedStores.map(async (store) => {
if (store.excludeFromBackendSync) return;
if (store.excludeFromBackendSync || dontAutoSync.includes(store.name)) return;
getKeyValue(store.name).then((currentKeyValue) => {
if (currentKeyValue !== null || allowNullOverwrite.includes(store.name)) {
if (currentKeyValue !== null) {
const currentKeyValueParsed = parseWithSchema(store.schema, currentKeyValue);
if (
(currentKeyValueParsed !== null && currentKeyValueParsed !== undefined) ||
allowNullOverwrite.includes(store.name)
) {
if (currentKeyValueParsed !== null && currentKeyValueParsed !== undefined) {
store.store.set(currentKeyValueParsed);
}
}
@@ -34,7 +31,7 @@ export async function syncSettingsToBackend() {
store.store.subscribe((value) => {
if (!get(rawMasterKeyStore)) return;
if (initialLoad && !allowNullOverwrite.includes(store.name)) {
if (initialLoad) {
initialLoad = false;
return;
}
File diff suppressed because one or more lines are too long