Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refactor(auth):configure-shared-auth-shells-and-migrate-pilot-pages

Aswin Asokcd378181b734
diff --git a/web/apps/auth/src/auth-page-config.ts b/web/apps/auth/src/auth-page-config.ts
new file mode 100644
index 0000000000..60c75c9748
--- /dev/null
+++ b/web/apps/auth/src/auth-page-config.ts
@@ -0,0 +1,4 @@
+import { AuthShell } from "@/components/AuthShell";
+import type { AuthPageConfig } from "ente-accounts/components/auth/AuthPageProvider";
+
+export const authPageConfig: AuthPageConfig = { Shell: AuthShell };
diff --git a/web/apps/auth/src/pages/_app.tsx b/web/apps/auth/src/pages/_app.tsx
index 6c76c26a62..d369a7a612 100644
--- a/web/apps/auth/src/pages/_app.tsx
+++ b/web/apps/auth/src/pages/_app.tsx
@@ -1,7 +1,9 @@
+import { authPageConfig } from "@/auth-page-config";
import "@fontsource-variable/inter";
import "@fontsource-variable/outfit";
import { CssBaseline } from "@mui/material";
import { ThemeProvider } from "@mui/material/styles";
+import { AuthPageProvider } from "ente-accounts/components/auth/AuthPageProvider";
import { savedLocalUser } from "ente-accounts/services/accounts-db";
import { accountLogout } from "ente-accounts/services/logout";
import { staticAppTitle } from "ente-base/app";
@@ -53,14 +55,16 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
<AttributedMiniDialog {...miniDialogProps} />
<BaseContext value={baseContext}>
- {!isI18nReady ? (
- <LoadingIndicator />
- ) : (
- <>
- {isChangingRoute && <TranslucentLoadingOverlay />}
- <Component {...pageProps} />
- </>
- )}
+ <AuthPageProvider value={authPageConfig}>
+ {!isI18nReady ? (
+ <LoadingIndicator />
+ ) : (
+ <>
+ {isChangingRoute && <TranslucentLoadingOverlay />}
+ <Component {...pageProps} />
+ </>
+ )}
+ </AuthPageProvider>
</BaseContext>
</ThemeProvider>
);
diff --git a/web/apps/auth/src/pages/signup.tsx b/web/apps/auth/src/pages/signup.tsx
index b8b5ef449b..fa3c32852a 100644
--- a/web/apps/auth/src/pages/signup.tsx
+++ b/web/apps/auth/src/pages/signup.tsx
@@ -1,13 +1 @@
-import { AuthShell } from "@/components/AuthShell";
-import { SignUpForm } from "ente-accounts/components/auth/SignUpForm";
-import { withAuthPageShell } from "ente-accounts/components/auth/withAuthPageShell";
-import AccountsSignUpPage from "ente-accounts/pages/signup";
-import type React from "react";
-
-const SignUpPresentation = withAuthPageShell(SignUpForm, AuthShell);
-
-function SignUpPage(): React.JSX.Element {
- return <AccountsSignUpPage presentation={SignUpPresentation} />;
-}
-
-export default SignUpPage;
+export { default } from "ente-accounts/pages/signup";
diff --git a/web/apps/locker/src/auth-page-config.ts b/web/apps/locker/src/auth-page-config.ts
new file mode 100644
index 0000000000..8ea1feabdf
--- /dev/null
+++ b/web/apps/locker/src/auth-page-config.ts
@@ -0,0 +1,4 @@
+import { LockerAuthShell } from "@/components/auth/LockerAuthShell";
+import type { AuthPageConfig } from "ente-accounts/components/auth/AuthPageProvider";
+
+export const authPageConfig: AuthPageConfig = { Shell: LockerAuthShell };
diff --git a/web/apps/locker/src/pages/_app.tsx b/web/apps/locker/src/pages/_app.tsx
index 4f98662dc6..9d97594884 100644
--- a/web/apps/locker/src/pages/_app.tsx
+++ b/web/apps/locker/src/pages/_app.tsx
@@ -1,9 +1,11 @@
+import { authPageConfig } from "@/auth-page-config";
import { LockerHead } from "@/components/LockerHead";
import { lockerLogout } from "@/services/logout";
import "@fontsource-variable/inter";
import "@fontsource-variable/outfit";
import { CssBaseline } from "@mui/material";
import { ThemeProvider } from "@mui/material/styles";
+import { AuthPageProvider } from "ente-accounts/components/auth/AuthPageProvider";
import {
isSavedUserTokenMismatch,
savedLocalUser,
@@ -71,14 +73,16 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {
<AttributedMiniDialog {...miniDialogProps} />
<BaseContext value={baseContext}>
- {!isI18nReady ? (
- <LoadingIndicator />
- ) : (
- <>
- {isChangingRoute && <TranslucentLoadingOverlay />}
- <Component {...pageProps} />
- </>
- )}
+ <AuthPageProvider value={authPageConfig}>
+ {!isI18nReady ? (
+ <LoadingIndicator />
+ ) : (
+ <>
+ {isChangingRoute && <TranslucentLoadingOverlay />}
+ <Component {...pageProps} />
+ </>
+ )}
+ </AuthPageProvider>
</BaseContext>
</ThemeProvider>
);
diff --git a/web/apps/locker/src/pages/signup.tsx b/web/apps/locker/src/pages/signup.tsx
index af48f70bdc..fa3c32852a 100644
--- a/web/apps/locker/src/pages/signup.tsx
+++ b/web/apps/locker/src/pages/signup.tsx
@@ -1,13 +1 @@
-import { LockerAuthShell } from "@/components/auth/LockerAuthShell";
-import { SignUpForm } from "ente-accounts/components/auth/SignUpForm";
-import { withAuthPageShell } from "ente-accounts/components/auth/withAuthPageShell";
-import AccountsSignUpPage from "ente-accounts/pages/signup";
-import type React from "react";
-
-const SignUpPresentation = withAuthPageShell(SignUpForm, LockerAuthShell);
-
-function SignUpPage(): React.JSX.Element {
- return <AccountsSignUpPage presentation={SignUpPresentation} />;
-}
-
-export default SignUpPage;
+export { default } from "ente-accounts/pages/signup";
diff --git a/web/apps/photos/src/auth-page-config.ts b/web/apps/photos/src/auth-page-config.ts
new file mode 100644
index 0000000000..ac685ccf6b
--- /dev/null
+++ b/web/apps/photos/src/auth-page-config.ts
@@ -0,0 +1,4 @@
+import { PhotosAuthShell } from "@/components/PhotosAuthShell";
+import type { AuthPageConfig } from "ente-accounts/components/auth/AuthPageProvider";
+
+export const authPageConfig: AuthPageConfig = { Shell: PhotosAuthShell };
diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsx
index 369db73379..317203109e 100644
--- a/web/apps/photos/src/pages/_app.tsx
+++ b/web/apps/photos/src/pages/_app.tsx
@@ -1,3 +1,4 @@
+import { authPageConfig } from "@/auth-page-config";
import { AppLockReauthenticationDialog } from "@/components/app-lock/AppLockReauthenticationDialog";
import { AppLockSetupError } from "@/components/app-lock/LockScreenContents";
import {
@@ -17,6 +18,7 @@ import "@fontsource-variable/outfit";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward";
import { CssBaseline, Typography } from "@mui/material";
import { styled, ThemeProvider, useColorScheme } from "@mui/material/styles";
+import { AuthPageProvider } from "ente-accounts/components/auth/AuthPageProvider";
import {
isLocalStorageAndIndexedDBMismatch,
savedLocalUser,
@@ -178,21 +180,23 @@ const App: React.FC<PhotosAppProps> = ({ Component, pageProps }) => {
)}
<BaseContext value={baseContext}>
<PhotosAppContext value={appContext}>
- {!isI18nReady ? (
- <LoadingIndicator />
- ) : isDesktop ? (
- <DesktopMainContent
- Component={Component}
- pageProps={pageProps}
- isChangingRoute={isChangingRoute}
- />
- ) : (
- <WebMainContent
- Component={Component}
- pageProps={pageProps}
- isChangingRoute={isChangingRoute}
- />
- )}
+ <AuthPageProvider value={authPageConfig}>
+ {!isI18nReady ? (
+ <LoadingIndicator />
+ ) : isDesktop ? (
+ <DesktopMainContent
+ Component={Component}
+ pageProps={pageProps}
+ isChangingRoute={isChangingRoute}
+ />
+ ) : (
+ <WebMainContent
+ Component={Component}
+ pageProps={pageProps}
+ isChangingRoute={isChangingRoute}
+ />
+ )}
+ </AuthPageProvider>
</PhotosAppContext>
</BaseContext>
</ThemeProvider>
diff --git a/web/apps/photos/src/pages/login.tsx b/web/apps/photos/src/pages/login.tsx
index 9d181c565c..675471334f 100644
--- a/web/apps/photos/src/pages/login.tsx
+++ b/web/apps/photos/src/pages/login.tsx
@@ -1,13 +1 @@
-import { PhotosAuthShell } from "@/components/PhotosAuthShell";
-import { LoginForm } from "ente-accounts/components/auth/LoginForm";
-import { withAuthPageShell } from "ente-accounts/components/auth/withAuthPageShell";
-import AccountsLoginPage from "ente-accounts/pages/login";
-import type React from "react";
-
-const LoginPresentation = withAuthPageShell(LoginForm, PhotosAuthShell);
-
-function LoginPage(): React.JSX.Element {
- return <AccountsLoginPage presentation={LoginPresentation} />;
-}
-
-export default LoginPage;
+export { default } from "ente-accounts/pages/login";
diff --git a/web/apps/photos/src/pages/signup.tsx b/web/apps/photos/src/pages/signup.tsx
index 35019c6b80..fa3c32852a 100644
--- a/web/apps/photos/src/pages/signup.tsx
+++ b/web/apps/photos/src/pages/signup.tsx
@@ -1,13 +1 @@
-import { PhotosAuthShell } from "@/components/PhotosAuthShell";
-import { SignUpForm } from "ente-accounts/components/auth/SignUpForm";
-import { withAuthPageShell } from "ente-accounts/components/auth/withAuthPageShell";
-import AccountsSignUpPage from "ente-accounts/pages/signup";
-import type React from "react";
-
-const SignUpPresentation = withAuthPageShell(SignUpForm, PhotosAuthShell);
-
-function SignUpPage(): React.JSX.Element {
- return <AccountsSignUpPage presentation={SignUpPresentation} />;
-}
-
-export default SignUpPage;
+export { default } from "ente-accounts/pages/signup";
diff --git a/web/packages/accounts/components/auth/AuthPageProvider.ts b/web/packages/accounts/components/auth/AuthPageProvider.ts
new file mode 100644
index 0000000000..0647c8a369
--- /dev/null
+++ b/web/packages/accounts/components/auth/AuthPageProvider.ts
@@ -0,0 +1,16 @@
+import { createContext, useContext, type ComponentType } from "react";
+import type { AuthPageShellProps } from "./AuthPageShell";
+
+/** App defaults for shared account pages, not reusable forms or dialogs. */
+export interface AuthPageConfig {
+ Shell?: ComponentType<
+ Pick<AuthPageShellProps, "children" | "contentWidth">
+ >;
+}
+
+const AuthPageContext = createContext<AuthPageConfig>({});
+
+export const AuthPageProvider = AuthPageContext.Provider;
+
+export const useAuthPageConfig = (): AuthPageConfig =>
+ useContext(AuthPageContext);
diff --git a/web/packages/accounts/pages/login.tsx b/web/packages/accounts/pages/login.tsx
index a92d3df176..f0cbe5ec5a 100644
--- a/web/packages/accounts/pages/login.tsx
+++ b/web/packages/accounts/pages/login.tsx
@@ -1,3 +1,5 @@
+import { useAuthPageConfig } from "ente-accounts/components/auth/AuthPageProvider";
+import { LoginForm } from "ente-accounts/components/auth/LoginForm";
import { AccountsPageContents } from "ente-accounts/components/layouts/centered-paper";
import {
LoginContents,
@@ -13,7 +15,10 @@ export interface LoginPageProps {
presentation?: React.ComponentType<LoginPresentationProps>;
}
-const Page: React.FC<LoginPageProps> = ({ presentation: Presentation }) => {
+const Page: React.FC<LoginPageProps> = ({ presentation }) => {
+ const { Shell } = useAuthPageConfig();
+ const Presentation =
+ presentation ?? (Shell ? ConfiguredLoginPresentation : undefined);
const [loading, setLoading] = useState(true);
const [host, setHost] = useState<string | undefined>(undefined);
@@ -39,3 +44,15 @@ const Page: React.FC<LoginPageProps> = ({ presentation: Presentation }) => {
};
export default Page;
+
+function ConfiguredLoginPresentation(
+ props: LoginPresentationProps,
+): React.JSX.Element {
+ // The page selects this presentation only when a shell is configured.
+ const Shell = useAuthPageConfig().Shell!;
+ return (
+ <Shell>
+ <LoginForm {...props} />
+ </Shell>
+ );
+}
diff --git a/web/packages/accounts/pages/signup.tsx b/web/packages/accounts/pages/signup.tsx
index b91edc37b3..698c51c8fa 100644
--- a/web/packages/accounts/pages/signup.tsx
+++ b/web/packages/accounts/pages/signup.tsx
@@ -1,3 +1,5 @@
+import { useAuthPageConfig } from "ente-accounts/components/auth/AuthPageProvider";
+import { SignUpForm } from "ente-accounts/components/auth/SignUpForm";
import { AccountsPageContents } from "ente-accounts/components/layouts/centered-paper";
import {
SignUpContents,
@@ -18,7 +20,13 @@ export interface SignUpPageProps {
presentation?: ComponentType<SignUpPresentationProps>;
}
-const Page: React.FC<SignUpPageProps> = ({ presentation }) => {
+const Page: React.FC<SignUpPageProps> = ({
+ presentation: explicitPresentation,
+}) => {
+ const { Shell } = useAuthPageConfig();
+ const presentation =
+ explicitPresentation ??
+ (Shell ? ConfiguredSignUpPresentation : undefined);
const [loading, setLoading] = useState(true);
const [host, setHost] = useState<string | undefined>(undefined);
@@ -44,3 +52,15 @@ const Page: React.FC<SignUpPageProps> = ({ presentation }) => {
};
export default Page;
+
+function ConfiguredSignUpPresentation(
+ props: SignUpPresentationProps,
+): React.JSX.Element {
+ // The page selects this presentation only when a shell is configured.
+ const Shell = useAuthPageConfig().Shell!;
+ return (
+ <Shell>
+ <SignUpForm {...props} />
+ </Shell>
+ );
+}