π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Migrate to fetch
Manav Rathi4d40f4975498
diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.tsindex e328338850..7afe88f19d 100644--- a/web/packages/accounts/services/user.ts+++ b/web/packages/accounts/services/user.ts@@ -1,5 +1,6 @@import { appName } from "@/base/app";import type { B64EncryptionResult } from "@/base/crypto/libsodium";+import { authenticatedRequestHeaders, ensureOk } from "@/base/http";import { apiURL } from "@/base/origins";import { ApiError, CustomError } from "@ente/shared/error";import HTTPService from "@ente/shared/network/HTTPService";@@ -82,6 +83,31 @@ export const putAttributes = async (},);+/**+ * Log the user out on remote, if possible and needed.+ */+export const remoteLogoutIfNeeded = async () => {+ let headers: HeadersInit;+ try {+ headers = await authenticatedRequestHeaders();+ } catch {+ // If the logout is attempted during the signup flow itself, then we+ // won't have an auth token.+ return;+ }++ const res = await fetch(await apiURL("/users/logout"), {+ method: "POST",+ headers,+ });+ if (!res.ok && res.status == 401) {+ // Ignore if we get a 401 Unauthorized, this is expected to happen on+ // token expiry.+ return;+ }+ ensureOk(res);+};+export const logout = async () => {try {const token = getToken();