diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-04-06 15:35:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-06 15:35:09 +0200 |
| commit | 0d4f19003324e196fffae3f252786e30197dfa4c (patch) | |
| tree | 08ba4eb3b0e067ae933c636ca3967c45058fd69f /opendc-web/opendc-web-ui/src/auth.js | |
| parent | af87540d49d58c465f0847c016814d58cfeb44fc (diff) | |
| parent | 9f0b7ddd0d62e4dc43a69ea8fafd06be1a663f9f (diff) | |
merge: Integrate UI into Quarkus web application (#69)
This pull request adds a Quarkus extension that integrates with the existing Quarkus web application to provide access to the OpenDC web UI. The benefit of this approach is that in this way, OpenDC can be distributed as a single JVM application to the user, which can host its own web UI directly.
Furthermore, this pull request also adds support for unauthenticated access to the API when accessing in dev mode, so that users do not have to setup Auth0 in order to use OpenDC locally.
## Implementation Notes :hammer_and_pick:
* Do not use next/image
* Migrate to next-global-css
* Update PatternFly to latest version
* Add Gradle integration with Next.js project
* Build web UI via Gradle
* Support building WebJar for OpenDC web UI
* Add extension for serving OpenDC web UI
* Include web UI in development mode
* Add workaround for Quarkus Gradle build issues
* Add support for unauthenticated user access
## External Dependencies :four_leaf_clover:
* [node-gradle](https://github.com/node-gradle/gradle-node-plugin)
Diffstat (limited to 'opendc-web/opendc-web-ui/src/auth.js')
| -rw-r--r-- | opendc-web/opendc-web-ui/src/auth.js | 42 |
1 files changed, 29 insertions, 13 deletions
diff --git a/opendc-web/opendc-web-ui/src/auth.js b/opendc-web/opendc-web-ui/src/auth.js index e670476c..3d6cf87c 100644 --- a/opendc-web/opendc-web-ui/src/auth.js +++ b/opendc-web/opendc-web-ui/src/auth.js @@ -23,15 +23,27 @@ import PropTypes from 'prop-types' import { Auth0Provider, useAuth0 } from '@auth0/auth0-react' import { useEffect } from 'react' +import { auth } from './config' /** - * Obtain the authentication context. + * Helper function to provide the authentication context in case Auth0 is not + * configured. */ -export function useAuth() { - return useAuth0() +function useAuthDev() { + return { + isAuthenticated: false, + isLoading: false, + logout: () => {}, + loginWithRedirect: () => {}, + } } /** + * Obtain the authentication context. + */ +export const useAuth = auth.domain ? useAuth0 : useAuthDev + +/** * Force the user to be authenticated or redirect to the homepage. */ export function useRequireAuth() { @@ -51,16 +63,20 @@ export function useRequireAuth() { * AuthProvider which provides an authentication context. */ export function AuthProvider({ children }) { - return ( - <Auth0Provider - domain={process.env.NEXT_PUBLIC_AUTH0_DOMAIN} - clientId={process.env.NEXT_PUBLIC_AUTH0_CLIENT_ID} - redirectUri={global.window && global.window.location.origin} - audience={process.env.NEXT_PUBLIC_AUTH0_AUDIENCE} - > - {children} - </Auth0Provider> - ) + if (auth.domain) { + return ( + <Auth0Provider + domain={auth.domain} + clientId={auth.clientId} + redirectUri={auth.redirectUri} + audience={auth.audience} + > + {children} + </Auth0Provider> + ) + } + + return children } AuthProvider.propTypes = { |
