diff --git a/web/src/beta/pages/Page.tsx b/web/src/beta/pages/Page.tsx index 5e0f587d61..d3b7d27812 100644 --- a/web/src/beta/pages/Page.tsx +++ b/web/src/beta/pages/Page.tsx @@ -1,8 +1,8 @@ import React, { ReactElement, ReactNode, useMemo } from "react"; import GlobalModal from "@reearth/classic/components/organisms/GlobalModal"; // todo: migrate to beta +import { AuthenticatedPage } from "@reearth/services/auth"; import { useMeFetcher, useProjectFetcher, useSceneFetcher } from "@reearth/services/api"; -import { AuthenticationRequiredPage } from "@reearth/services/auth"; import { useTheme } from "@reearth/services/theme"; import Loading from "../components/Loading"; @@ -61,11 +61,11 @@ const PageWrapper: React.FC = ({ sceneId, projectId, workspaceId, childre }; const Page: React.FC = ({ sceneId, projectId, workspaceId, children }) => ( - + {children} - + ); export default Page; diff --git a/web/src/classic/components/pages/Dashboard/index.tsx b/web/src/classic/components/pages/Dashboard/index.tsx index e680813ab5..e676082a5b 100644 --- a/web/src/classic/components/pages/Dashboard/index.tsx +++ b/web/src/classic/components/pages/Dashboard/index.tsx @@ -2,7 +2,7 @@ import React from "react"; import { useParams } from "react-router-dom"; import Dashboard from "@reearth/classic/components/organisms/Dashboard"; -import { AuthenticationRequiredPage, withAuthorisation } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; export type Props = { path?: string; @@ -11,10 +11,10 @@ export type Props = { const DashboardPage: React.FC = () => { const { workspaceId } = useParams(); return ( - + - + ); }; -export default withAuthorisation()(DashboardPage); +export default DashboardPage; diff --git a/web/src/classic/components/pages/EarthEditor/index.tsx b/web/src/classic/components/pages/EarthEditor/index.tsx index c1477d386c..51e0c780fb 100644 --- a/web/src/classic/components/pages/EarthEditor/index.tsx +++ b/web/src/classic/components/pages/EarthEditor/index.tsx @@ -11,7 +11,7 @@ import PrimitiveHeader from "@reearth/classic/components/organisms/EarthEditor/P import RightMenu from "@reearth/classic/components/organisms/EarthEditor/RightMenu"; import { useCore } from "@reearth/classic/util/use-core"; import { Provider as DndProvider } from "@reearth/classic/util/use-dnd"; -import { withAuthorisation, AuthenticationRequiredPage } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; import useHooks from "./hooks"; @@ -25,7 +25,7 @@ const EarthEditor: React.FC = () => { const core = useCore("earth_editor"); return ( - + = () => { right={} /> - + ); }; -export default withAuthorisation()(EarthEditor); +export default EarthEditor; diff --git a/web/src/classic/components/pages/Preview/index.tsx b/web/src/classic/components/pages/Preview/index.tsx index 9ddef9f3c4..eb94f924c8 100644 --- a/web/src/classic/components/pages/Preview/index.tsx +++ b/web/src/classic/components/pages/Preview/index.tsx @@ -5,7 +5,7 @@ import CanvasArea from "@reearth/classic/components/organisms/EarthEditor/Canvas import CoreCanvasArea from "@reearth/classic/components/organisms/EarthEditor/core/CanvasArea"; import { useCore } from "@reearth/classic/util/use-core"; import { Provider as DndProvider } from "@reearth/classic/util/use-dnd"; -import { withAuthorisation, AuthenticationRequiredPage } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; import { useSceneId } from "@reearth/services/state"; import { PublishedAppProvider as ThemeProvider } from "@reearth/services/theme"; @@ -25,12 +25,12 @@ const PreviewPage: React.FC = () => { return sceneId2 ? ( - + {typeof core === "boolean" && (core ? : )} - + ) : null; }; -export default withAuthorisation()(PreviewPage); +export default PreviewPage; diff --git a/web/src/classic/components/pages/Settings/Account/index.tsx b/web/src/classic/components/pages/Settings/Account/index.tsx index 3294b60d99..cabb92898e 100644 --- a/web/src/classic/components/pages/Settings/Account/index.tsx +++ b/web/src/classic/components/pages/Settings/Account/index.tsx @@ -1,16 +1,16 @@ import React from "react"; import Account from "@reearth/classic/components/organisms/Settings/Account"; -import { AuthenticationRequiredPage, withAuthorisation } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; export type Props = { path?: string; }; const AccountPage: React.FC = () => ( - + - + ); -export default withAuthorisation()(AccountPage); +export default AccountPage; diff --git a/web/src/classic/components/pages/Settings/Project/Dataset/index.tsx b/web/src/classic/components/pages/Settings/Project/Dataset/index.tsx index a1c6c0eb7f..24f447d95d 100644 --- a/web/src/classic/components/pages/Settings/Project/Dataset/index.tsx +++ b/web/src/classic/components/pages/Settings/Project/Dataset/index.tsx @@ -2,7 +2,7 @@ import React from "react"; import { useParams } from "react-router-dom"; import Dataset from "@reearth/classic/components/organisms/Settings/Project/Dataset"; -import { AuthenticationRequiredPage, withAuthorisation } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; export type Props = { path?: string; @@ -11,10 +11,10 @@ export type Props = { const DatasetPage: React.FC = () => { const { projectId = "" } = useParams(); return ( - + - + ); }; -export default withAuthorisation()(DatasetPage); +export default DatasetPage; diff --git a/web/src/classic/components/pages/Settings/Project/Plugin/index.tsx b/web/src/classic/components/pages/Settings/Project/Plugin/index.tsx index 48dc25028e..7bf5f3076d 100644 --- a/web/src/classic/components/pages/Settings/Project/Plugin/index.tsx +++ b/web/src/classic/components/pages/Settings/Project/Plugin/index.tsx @@ -2,7 +2,7 @@ import React from "react"; import { useParams } from "react-router-dom"; import Plugin from "@reearth/classic/components/organisms/Settings/Project/Plugin"; -import { AuthenticationRequiredPage, withAuthorisation } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; export type Props = { path?: string; @@ -11,10 +11,10 @@ export type Props = { const PluginPage: React.FC = () => { const { projectId = "" } = useParams(); return ( - + ; - + ); }; -export default withAuthorisation()(PluginPage); +export default PluginPage; diff --git a/web/src/classic/components/pages/Settings/Project/Public/index.tsx b/web/src/classic/components/pages/Settings/Project/Public/index.tsx index 8ee84bd96d..09a4b875ac 100644 --- a/web/src/classic/components/pages/Settings/Project/Public/index.tsx +++ b/web/src/classic/components/pages/Settings/Project/Public/index.tsx @@ -2,7 +2,7 @@ import React from "react"; import { useParams } from "react-router-dom"; import Public from "@reearth/classic/components/organisms/Settings/Project/Public"; -import { AuthenticationRequiredPage, withAuthorisation } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; export type Props = { path?: string; @@ -11,10 +11,10 @@ export type Props = { const PublicPage: React.FC = () => { const { projectId = "" } = useParams(); return ( - + - + ); }; -export default withAuthorisation()(PublicPage); +export default PublicPage; diff --git a/web/src/classic/components/pages/Settings/Project/index.tsx b/web/src/classic/components/pages/Settings/Project/index.tsx index 27d01fce6e..97bf5d878c 100644 --- a/web/src/classic/components/pages/Settings/Project/index.tsx +++ b/web/src/classic/components/pages/Settings/Project/index.tsx @@ -2,7 +2,7 @@ import React from "react"; import { useParams } from "react-router-dom"; import Project from "@reearth/classic/components/organisms/Settings/Project"; -import { AuthenticationRequiredPage, withAuthorisation } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; export type Props = { path?: string; @@ -11,10 +11,10 @@ export type Props = { const ProjectPage: React.FC = () => { const { projectId = "" } = useParams(); return ( - + - + ); }; -export default withAuthorisation()(ProjectPage); +export default ProjectPage; diff --git a/web/src/classic/components/pages/Settings/ProjectList/index.tsx b/web/src/classic/components/pages/Settings/ProjectList/index.tsx index 044d738127..629c4112dc 100644 --- a/web/src/classic/components/pages/Settings/ProjectList/index.tsx +++ b/web/src/classic/components/pages/Settings/ProjectList/index.tsx @@ -2,7 +2,6 @@ import React from "react"; import { useParams } from "react-router-dom"; import OrganismsProjectList from "@reearth/classic/components/organisms/Settings/ProjectList"; -import { withAuthorisation } from "@reearth/services/auth"; export interface Props { path?: string; @@ -13,4 +12,4 @@ const ProjectList: React.FC = () => { return ; }; -export default withAuthorisation()(ProjectList); +export default ProjectList; diff --git a/web/src/classic/components/pages/Settings/Workspace/Asset/index.tsx b/web/src/classic/components/pages/Settings/Workspace/Asset/index.tsx index ea573050ca..153d131509 100644 --- a/web/src/classic/components/pages/Settings/Workspace/Asset/index.tsx +++ b/web/src/classic/components/pages/Settings/Workspace/Asset/index.tsx @@ -2,7 +2,7 @@ import React from "react"; import { useParams } from "react-router-dom"; import Asset from "@reearth/classic/components/organisms/Settings/Workspace/Asset"; -import { AuthenticationRequiredPage, withAuthorisation } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; export type Props = { path?: string; @@ -11,10 +11,10 @@ export type Props = { const AssetPage: React.FC = () => { const { workspaceId = "" } = useParams(); return ( - + - + ); }; -export default withAuthorisation()(AssetPage); +export default AssetPage; diff --git a/web/src/classic/components/pages/Settings/Workspace/index.tsx b/web/src/classic/components/pages/Settings/Workspace/index.tsx index a971d5bc14..a599cf73e7 100644 --- a/web/src/classic/components/pages/Settings/Workspace/index.tsx +++ b/web/src/classic/components/pages/Settings/Workspace/index.tsx @@ -2,7 +2,7 @@ import React from "react"; import { useParams } from "react-router-dom"; import Workspace from "@reearth/classic/components/organisms/Settings/Workspace"; -import { AuthenticationRequiredPage, withAuthorisation } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; export type Props = { path?: string; @@ -11,10 +11,10 @@ export type Props = { const WorkspacePage: React.FC = () => { const { workspaceId = "" } = useParams(); return ( - + - + ); }; -export default withAuthorisation()(WorkspacePage); +export default WorkspacePage; diff --git a/web/src/classic/components/pages/Settings/WorkspaceList/index.tsx b/web/src/classic/components/pages/Settings/WorkspaceList/index.tsx index d4a206785a..90331af780 100644 --- a/web/src/classic/components/pages/Settings/WorkspaceList/index.tsx +++ b/web/src/classic/components/pages/Settings/WorkspaceList/index.tsx @@ -2,7 +2,7 @@ import React from "react"; import { useParams } from "react-router-dom"; import OrganismsWorkspaceList from "@reearth/classic/components/organisms/Settings/WorkspaceList"; -import { AuthenticationRequiredPage, withAuthorisation } from "@reearth/services/auth"; +import { AuthenticatedPage } from "@reearth/services/auth"; export type Props = { path?: string; @@ -11,10 +11,10 @@ export type Props = { const WorkspaceList: React.FC = () => { const { workspaceId = "" } = useParams(); return ( - + - + ); }; -export default withAuthorisation()(WorkspaceList); +export default WorkspaceList; diff --git a/web/src/services/auth/authProvider.tsx b/web/src/services/auth/authProvider.tsx index a2e36916b6..6deec5355f 100644 --- a/web/src/services/auth/authProvider.tsx +++ b/web/src/services/auth/authProvider.tsx @@ -1,5 +1,5 @@ import { Auth0Provider } from "@auth0/auth0-react"; -import React, { createContext, ReactNode } from "react"; +import React, { createContext, ReactNode, Fragment } from "react"; import type { AuthHook } from "./authHook"; import { useAuth0Auth } from "./authOAuth"; @@ -47,5 +47,5 @@ export const AuthProvider: React.FC<{ children?: ReactNode }> = ({ children }) = return {children}; } - return <>{children}; // or some default fallback + return {children}; // or some default fallback }; diff --git a/web/src/services/auth/index.tsx b/web/src/services/auth/index.tsx index 3b07503c92..ee1dda0215 100644 --- a/web/src/services/auth/index.tsx +++ b/web/src/services/auth/index.tsx @@ -7,17 +7,19 @@ import { useAuthenticationRequired } from "./useAuth"; export { AuthProvider } from "./authProvider"; export { useAuth, useCleanUrl, useAuthenticationRequired } from "./useAuth"; -export const AuthenticationRequiredPage: React.FC<{ children?: ReactNode }> = ({ children }) => { +const AuthenticationRequiredPage: React.FC<{ children?: ReactNode }> = ({ children }) => { const [isAuthenticated] = useAuthenticationRequired(); // TODO: show error return isAuthenticated && children ? <>{children} : null; }; -export const withAuthorisation = (): ((props: any) => React.FC) => { +const withAuthorisation = (): ((props: any) => React.FC) => { const authProvider = window.REEARTH_CONFIG?.authProvider; - if (authProvider === "cognito") { return withAuthenticator as unknown as (props: any) => React.FC; + } else if (authProvider === "auth0") { + return withAuthenticationRequired as unknown as (props: any) => React.FC; } - - return withAuthenticationRequired as unknown as (props: any) => React.FC; + return (props: any) => props; }; + +export const AuthenticatedPage = withAuthorisation()(AuthenticationRequiredPage);