Skip to content

Commit

Permalink
fix: Updates test apps login form now that useUser is available
Browse files Browse the repository at this point in the history
* useUser hook exported from hawtio/react so can fix the login process
  when using form-login mode in the test apps

* Test login pages need to wait from the userService to complete before
  trying to load the login form

* Logic based entirely on the hawtio/next login form
  • Loading branch information
phantomjinx committed Nov 20, 2023
1 parent 326d7af commit df19492
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
21 changes: 16 additions & 5 deletions packages/kubernetes-api-app/src/login/AuthLoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import React from 'react'
import { usePlugins, DEFAULT_APP_NAME, useHawtconfig } from '@hawtio/react'
import { usePlugins, DEFAULT_APP_NAME, useHawtconfig, useUser } from '@hawtio/react'
import { backgroundImages, hawtioLogo } from './img'
import { ListItem, ListVariant, LoginFooterItem, LoginPage } from '@patternfly/react-core'
import { log } from '@hawtio/online-oauth'
import { AuthLoadingPage } from './AuthLoadingPage'
import { useNavigate } from 'react-router-dom'

export const AuthLoginPage: React.FunctionComponent = () => {
const navigate = useNavigate()

const { isLogin, userLoaded } = useUser()
const { hawtconfig, hawtconfigLoaded } = useHawtconfig()
const { plugins, pluginsLoaded } = usePlugins()

if (!hawtconfigLoaded && !pluginsLoaded) {
if (!userLoaded || !hawtconfigLoaded || !pluginsLoaded) {
log.debug('Loading:, hawtconfig =', hawtconfigLoaded, ', plugins =', pluginsLoaded)
return <AuthLoadingPage />
}

if (isLogin) {
navigate('/')
}

let loginForm = null
const loginPlugins = plugins.filter(plugin => plugin.isLogin)
log.debug('Discovered Login Plugins:', loginPlugins.length)

if (loginPlugins.length > 0) {
log.debug('Found Login Plugins ... Customising the Login Page')

const loginPlugin = loginPlugins[0]
const component = loginPlugin?.component
if (!component) {
log.info('Custom login component not defined: ', loginPlugin?.id)
} else {
if (component) {
log.debug('Building with customised login form component')
loginForm = React.createElement(component)
}
}
Expand Down
21 changes: 16 additions & 5 deletions packages/management-api-app/src/login/AuthLoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import React from 'react'
import { usePlugins, DEFAULT_APP_NAME, useHawtconfig } from '@hawtio/react'
import { usePlugins, DEFAULT_APP_NAME, useHawtconfig, useUser } from '@hawtio/react'
import { backgroundImages, hawtioLogo } from './img'
import { ListItem, ListVariant, LoginFooterItem, LoginPage } from '@patternfly/react-core'
import { log } from '@hawtio/online-oauth'
import { AuthLoadingPage } from './AuthLoadingPage'
import { useNavigate } from 'react-router-dom'

export const AuthLoginPage: React.FunctionComponent = () => {
const navigate = useNavigate()

const { isLogin, userLoaded } = useUser()
const { hawtconfig, hawtconfigLoaded } = useHawtconfig()
const { plugins, pluginsLoaded } = usePlugins()

if (!hawtconfigLoaded && !pluginsLoaded) {
if (!userLoaded || !hawtconfigLoaded || !pluginsLoaded) {
log.debug('Loading:, hawtconfig =', hawtconfigLoaded, ', plugins =', pluginsLoaded)
return <AuthLoadingPage />
}

if (isLogin) {
navigate('/')
}

let loginForm = null
const loginPlugins = plugins.filter(plugin => plugin.isLogin)
log.debug('Discovered Login Plugins:', loginPlugins.length)

if (loginPlugins.length > 0) {
log.debug('Found Login Plugins ... Customising the Login Page')

const loginPlugin = loginPlugins[0]
const component = loginPlugin?.component
if (!component) {
log.info('Custom login component not defined: ', loginPlugin?.id)
} else {
if (component) {
log.debug('Building with customised login form component')
loginForm = React.createElement(component)
}
}
Expand Down
21 changes: 16 additions & 5 deletions packages/oauth-app/src/login/AuthLoginPage.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import React from 'react'
import { usePlugins, DEFAULT_APP_NAME, useHawtconfig } from '@hawtio/react'
import { usePlugins, DEFAULT_APP_NAME, useHawtconfig, useUser } from '@hawtio/react'
import { backgroundImages, hawtioLogo } from './img'
import { ListItem, ListVariant, LoginFooterItem, LoginPage } from '@patternfly/react-core'
import { log } from '@hawtio/online-oauth'
import { AuthLoadingPage } from './AuthLoadingPage'
import { useNavigate } from 'react-router-dom'

export const AuthLoginPage: React.FunctionComponent = () => {
const navigate = useNavigate()

const { isLogin, userLoaded } = useUser()
const { hawtconfig, hawtconfigLoaded } = useHawtconfig()
const { plugins, pluginsLoaded } = usePlugins()

if (!hawtconfigLoaded && !pluginsLoaded) {
if (!userLoaded || !hawtconfigLoaded || !pluginsLoaded) {
log.debug('Loading:, hawtconfig =', hawtconfigLoaded, ', plugins =', pluginsLoaded)
return <AuthLoadingPage />
}

if (isLogin) {
navigate('/')
}

let loginForm = null
const loginPlugins = plugins.filter(plugin => plugin.isLogin)
log.debug('Discovered Login Plugins:', loginPlugins.length)

if (loginPlugins.length > 0) {
log.debug('Found Login Plugins ... Customising the Login Page')

const loginPlugin = loginPlugins[0]
const component = loginPlugin?.component
if (!component) {
log.info('Custom login component not defined: ', loginPlugin?.id)
} else {
if (component) {
log.debug('Building with customised login form component')
loginForm = React.createElement(component)
}
}
Expand Down

0 comments on commit df19492

Please sign in to comment.