summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/pages
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-16 23:18:02 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-05-18 15:46:42 +0200
commita6865b86cc8d710374fc0b6cfcbd2b863f1942a9 (patch)
tree121fdb26827c5509a12a4427e8f9d881dbdefe82 /opendc-web/opendc-web-ui/src/pages
parent6412610f38117e1ea0635a56fa023183723fa67a (diff)
ui: Migrate to Auth0 as Identity Provider
This change updates the frontend codebase to move away from the Google login and instead use Auth0 as generic Identity Provider. This allows users to login with other accounts as well. Since Auth0 has a free tier, users can experiment themselves with OpenDC locally without having to pay for the login functionality. The code has been written so that we should be able to migrate away from Auth0 once it is not a suitable Identity Provider for OpenDC anymore.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/pages')
-rw-r--r--opendc-web/opendc-web-ui/src/pages/_app.js20
-rw-r--r--opendc-web/opendc-web-ui/src/pages/logout.js39
-rw-r--r--opendc-web/opendc-web-ui/src/pages/profile.js76
-rw-r--r--opendc-web/opendc-web-ui/src/pages/projects/index.js8
4 files changed, 58 insertions, 85 deletions
diff --git a/opendc-web/opendc-web-ui/src/pages/_app.js b/opendc-web/opendc-web-ui/src/pages/_app.js
index 761ae0cd..f9727a7a 100644
--- a/opendc-web/opendc-web-ui/src/pages/_app.js
+++ b/opendc-web/opendc-web-ui/src/pages/_app.js
@@ -24,19 +24,29 @@ import Head from 'next/head'
import { Provider } from 'react-redux'
import { useStore } from '../redux'
import '../index.scss'
+import { AuthProvider, useAuth } from '../auth'
-export default function App({ Component, pageProps }) {
- const store = useStore(pageProps.initialReduxState)
+// This setup is necessary to forward the Auth0 context to the Redux context
+const Inner = ({ Component, pageProps }) => {
+ const auth = useAuth()
+ const store = useStore(pageProps.initialReduxState, { auth })
+ return (
+ <Provider store={store}>
+ <Component {...pageProps} />
+ </Provider>
+ )
+}
+export default function App(props) {
return (
<>
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="theme-color" content="#00A6D6" />
</Head>
- <Provider store={store}>
- <Component {...pageProps} />
- </Provider>
+ <AuthProvider>
+ <Inner {...props} />
+ </AuthProvider>
</>
)
}
diff --git a/opendc-web/opendc-web-ui/src/pages/logout.js b/opendc-web/opendc-web-ui/src/pages/logout.js
new file mode 100644
index 00000000..e96e0605
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/pages/logout.js
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2021 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import React from 'react'
+import Head from 'next/head'
+import AppNavbarContainer from '../containers/navigation/AppNavbarContainer'
+
+function Logout() {
+ return (
+ <>
+ <Head>
+ <title>Logged Out - OpenDC</title>
+ </Head>
+ <AppNavbarContainer fullWidth={false} />
+ <span>Logged out successfully</span>
+ </>
+ )
+}
+
+export default Logout
diff --git a/opendc-web/opendc-web-ui/src/pages/profile.js b/opendc-web/opendc-web-ui/src/pages/profile.js
deleted file mode 100644
index 97afc4d9..00000000
--- a/opendc-web/opendc-web-ui/src/pages/profile.js
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (c) 2021 AtLarge Research
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-import React, { useState } from 'react'
-import Head from 'next/head'
-import { useDispatch } from 'react-redux'
-import AppNavbarContainer from '../containers/navigation/AppNavbarContainer'
-import ConfirmationModal from '../components/modals/ConfirmationModal'
-import { deleteCurrentUser } from '../redux/actions/users'
-import { useRequireAuth } from '../auth'
-
-const Profile = () => {
- useRequireAuth()
-
- const dispatch = useDispatch()
-
- const [isDeleteModalOpen, setDeleteModalOpen] = useState(false)
- const onDelete = (isConfirmed) => {
- if (isConfirmed) {
- dispatch(deleteCurrentUser())
- }
- setDeleteModalOpen(false)
- }
-
- return (
- <>
- <Head>
- <title>My Profile - OpenDC</title>
- </Head>
- <div className="full-height">
- <AppNavbarContainer fullWidth={false} />
- <div className="container text-page-container full-height">
- <button
- className="btn btn-danger mb-2 ml-auto mr-auto"
- style={{ maxWidth: 300 }}
- onClick={() => setDeleteModalOpen(true)}
- >
- Delete my account on OpenDC
- </button>
- <p className="text-muted text-center">
- This does not delete your Google account, but simply disconnects it from the OpenDC platform and
- deletes any project info that is associated with you (projects you own and any authorizations
- you may have on other projects).
- </p>
- </div>
- <ConfirmationModal
- title="Delete my account"
- message="Are you sure you want to delete your OpenDC account?"
- show={isDeleteModalOpen}
- callback={onDelete}
- />
- </div>
- </>
- )
-}
-
-export default Profile
diff --git a/opendc-web/opendc-web-ui/src/pages/projects/index.js b/opendc-web/opendc-web-ui/src/pages/projects/index.js
index 05e9514f..8603c228 100644
--- a/opendc-web/opendc-web-ui/src/pages/projects/index.js
+++ b/opendc-web/opendc-web-ui/src/pages/projects/index.js
@@ -1,13 +1,13 @@
import React, { useEffect, useState } from 'react'
import Head from 'next/head'
import { useDispatch } from 'react-redux'
-import { fetchAuthorizationsOfCurrentUser } from '../../redux/actions/users'
import ProjectFilterPanel from '../../components/projects/FilterPanel'
import NewProjectContainer from '../../containers/projects/NewProjectContainer'
-import VisibleProjectList from '../../containers/projects/VisibleProjectAuthList'
+import ProjectListContainer from '../../containers/projects/ProjectListContainer'
import AppNavbarContainer from '../../containers/navigation/AppNavbarContainer'
import { useRequireAuth } from '../../auth'
import { Container } from 'reactstrap'
+import { fetchProjects } from '../../redux/actions/projects'
function Projects() {
useRequireAuth()
@@ -15,7 +15,7 @@ function Projects() {
const dispatch = useDispatch()
const [filter, setFilter] = useState('SHOW_ALL')
- useEffect(() => dispatch(fetchAuthorizationsOfCurrentUser()), [])
+ useEffect(() => dispatch(fetchProjects()), [])
return (
<>
@@ -26,7 +26,7 @@ function Projects() {
<AppNavbarContainer fullWidth={false} />
<Container className="text-page-container">
<ProjectFilterPanel onSelect={setFilter} activeFilter={filter} />
- <VisibleProjectList filter={filter} />
+ <ProjectListContainer filter={filter} />
<NewProjectContainer />
</Container>
</div>