Migrate
This commit is contained in:
@@ -33,7 +33,7 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
|
||||
useEffect(() => {
|
||||
disableDiskLogs();
|
||||
// The accounts app has no local state, but some older builds might've
|
||||
// leftover some scraps. Clear it out. Thi code added 1 July 2024, can
|
||||
// leftover some scraps. Clear it out. This code added 1 July 2024, can
|
||||
// be removed after a while (tag: Migration).
|
||||
clearData();
|
||||
void setupI18n().finally(() => setIsI18nReady(true));
|
||||
|
||||
@@ -17,7 +17,11 @@ import { AppNavbar } from "@ente/shared/components/Navbar/app";
|
||||
import { PHOTOS_PAGES as PAGES } from "@ente/shared/constants/pages";
|
||||
import { useLocalState } from "@ente/shared/hooks/useLocalState";
|
||||
import HTTPService from "@ente/shared/network/HTTPService";
|
||||
import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
|
||||
import {
|
||||
LS_KEYS,
|
||||
getData,
|
||||
setKVToken,
|
||||
} from "@ente/shared/storage/localStorage";
|
||||
import { getTheme } from "@ente/shared/themes";
|
||||
import { THEME_COLOR } from "@ente/shared/themes/constants";
|
||||
import type { User } from "@ente/shared/user/types";
|
||||
@@ -75,8 +79,9 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
|
||||
|
||||
useEffect(() => {
|
||||
void setupI18n().finally(() => setIsI18nReady(true));
|
||||
const userID = (getData(LS_KEYS.USER) as User)?.id;
|
||||
logStartupBanner(userID);
|
||||
const user = getData(LS_KEYS.USER) as User | undefined | null;
|
||||
setKVToken(user);
|
||||
logStartupBanner(user?.id);
|
||||
HTTPService.setHeaders({ "X-Client-Package": clientPackageName });
|
||||
logUnhandledErrorsAndRejections(true);
|
||||
return () => logUnhandledErrorsAndRejections(false);
|
||||
|
||||
@@ -23,7 +23,11 @@ import { AppNavbar } from "@ente/shared/components/Navbar/app";
|
||||
import { PHOTOS_PAGES as PAGES } from "@ente/shared/constants/pages";
|
||||
import { useLocalState } from "@ente/shared/hooks/useLocalState";
|
||||
import HTTPService from "@ente/shared/network/HTTPService";
|
||||
import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
|
||||
import {
|
||||
LS_KEYS,
|
||||
getData,
|
||||
setKVToken,
|
||||
} from "@ente/shared/storage/localStorage";
|
||||
import {
|
||||
getLocalMapEnabled,
|
||||
getToken,
|
||||
@@ -140,8 +144,9 @@ export default function App({ Component, pageProps }: AppProps) {
|
||||
|
||||
useEffect(() => {
|
||||
void setupI18n().finally(() => setIsI18nReady(true));
|
||||
const userID = (getData(LS_KEYS.USER) as User)?.id;
|
||||
logStartupBanner(userID);
|
||||
const user = getData(LS_KEYS.USER) as User | undefined | null;
|
||||
setKVToken(user);
|
||||
logStartupBanner(user?.id);
|
||||
HTTPService.setHeaders({ "X-Client-Package": clientPackageName });
|
||||
logUnhandledErrorsAndRejections(true);
|
||||
return () => logUnhandledErrorsAndRejections(false);
|
||||
|
||||
@@ -54,9 +54,23 @@ export const clearData = () => localStorage.clear();
|
||||
//
|
||||
// Creating a new function here to act as a funnel point.
|
||||
export const setLSUser = async (user: object) => {
|
||||
const token = user["token"];
|
||||
await setKVToken(user);
|
||||
setData(LS_KEYS.USER, user);
|
||||
};
|
||||
|
||||
/**
|
||||
* Update the "token" KV with the token (if any) for the given {@link user}.
|
||||
*
|
||||
* This is an internal implementation details of {@link setLSUser} and doesn't
|
||||
* need to exposed conceptually. For now though, we need to call this externally
|
||||
* at an early point in the app startup to also copy over the token into KV DB
|
||||
* for existing users.
|
||||
*
|
||||
* This was added 1 July 2024, can be removed after a while (tag: Migration).
|
||||
*/
|
||||
export const setKVToken = async (user: unknown) => {
|
||||
const token = user ? user["token"] : undefined;
|
||||
token && typeof token == "string"
|
||||
? await setKV("token", token)
|
||||
: await removeKV("token");
|
||||
setData(LS_KEYS.USER, user);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user