π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Read from kv
Manav Rathi0376af8d3853
diff --git a/web/packages/accounts/services/session.ts b/web/packages/accounts/services/session.tsindex d82f12ebd9..386e1290b9 100644--- a/web/packages/accounts/services/session.ts+++ b/web/packages/accounts/services/session.ts@@ -64,7 +64,7 @@ type SessionValidity =export const checkSessionValidity = async (): Promise<SessionValidity> => {const url = await apiURL("/users/session-validity/v2");const res = await fetch(url, {- headers: authenticatedRequestHeaders(),+ headers: await authenticatedRequestHeaders(),});if (!res.ok) {if (res.status == 401)diff --git a/web/packages/new/photos/services/embedding.ts b/web/packages/new/photos/services/embedding.tsindex 82de19ec9d..a8d27f7177 100644--- a/web/packages/new/photos/services/embedding.ts+++ b/web/packages/new/photos/services/embedding.ts@@ -332,7 +332,7 @@ const getEmbeddingsDiff = async (});const url = await apiURL("/embeddings/diff");const res = await fetch(`${url}?${params.toString()}`, {- headers: authenticatedRequestHeaders(),+ headers: await authenticatedRequestHeaders(),});if (!res.ok) throw new Error(`Failed to fetch ${url}: HTTP ${res.status}`);return z.array(RemoteEmbedding).parse(await res.json());diff --git a/web/packages/new/photos/services/feature-flags.ts b/web/packages/new/photos/services/feature-flags.tsindex 97969d1a41..b5d75936db 100644--- a/web/packages/new/photos/services/feature-flags.ts+++ b/web/packages/new/photos/services/feature-flags.ts@@ -67,7 +67,7 @@ const fetchAndSaveFeatureFlags = () =>const fetchFeatureFlags = async () => {const url = await apiURL("/remote-store/feature-flags");const res = await fetch(url, {- headers: authenticatedRequestHeaders(),+ headers: await authenticatedRequestHeaders(),});if (!res.ok) throw new Error(`Failed to fetch ${url}: HTTP ${res.status}`);return res;diff --git a/web/packages/next/http.ts b/web/packages/next/http.tsindex fca7bbfc6b..d7a731a487 100644--- a/web/packages/next/http.ts+++ b/web/packages/next/http.ts@@ -8,8 +8,8 @@ import { ensureAuthToken } from "./local-user";* - The auth token* - The client package name.*/-export const authenticatedRequestHeaders = (): Record<string, string> => ({- "X-Auth-Token": ensureAuthToken(),+export const authenticatedRequestHeaders = async () => ({+ "X-Auth-Token": await ensureAuthToken(),"X-Client-Package": clientPackageName,});@@ -17,6 +17,6 @@ export const authenticatedRequestHeaders = (): Record<string, string> => ({* Return a headers object with "X-Client-Package" header set to the client* package name of the current app.*/-export const clientPackageHeader = (): Record<string, string> => ({+export const clientPackageHeader = () => ({"X-Client-Package": clientPackageName,});diff --git a/web/packages/next/local-user.ts b/web/packages/next/local-user.tsindex e7bf356c15..d38ed5a69c 100644--- a/web/packages/next/local-user.ts+++ b/web/packages/next/local-user.ts@@ -1,5 +1,8 @@// TODO: This file belongs to the accounts package++import { ensure } from "@/utils/ensure";import { z } from "zod";+import { getKV } from "./kv";// TODO: During login the only field present is email. Which makes this// optionality indicated by these types incorrect.@@ -45,10 +48,13 @@ export const ensureLocalUser = (): LocalUser => {/*** Return the user's auth token, or throw an error.*- * The user's auth token is stored in local storage after they have successfully- * logged in. This function returns that saved auth token.+ * The user's auth token is stored in KV DB after they have successfully logged+ * in. This function returns that saved auth token.** If no such token is found (which should only happen if the user is not logged* in), then it throws an error.+ *+ * The underlying data is stored in IndexedDB, and can be accessed from web+ * workers.*/-export const ensureAuthToken = (): string => ensureLocalUser().token;+export const ensureAuthToken = async () => ensure(await getKV("token"));