From 68d9003f8d8d2adcba43cad6366eca5365110e48 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Tue, 5 Apr 2022 21:15:57 +0200 Subject: feat(web/ui): Add support for unauthenticated user access This change updates the web UI and API to support unauthenticated user access. Such functionality is helpful when there is just a single user that wants to try OpenDC. --- .../opendc-web-ui/src/components/AppHeaderTools.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'opendc-web/opendc-web-ui/src/components/AppHeaderTools.js') diff --git a/opendc-web/opendc-web-ui/src/components/AppHeaderTools.js b/opendc-web/opendc-web-ui/src/components/AppHeaderTools.js index 02e5d265..3e58b209 100644 --- a/opendc-web/opendc-web-ui/src/components/AppHeaderTools.js +++ b/opendc-web/opendc-web-ui/src/components/AppHeaderTools.js @@ -39,7 +39,9 @@ import { useAuth } from '../auth' import { GithubIcon, HelpIcon } from '@patternfly/react-icons' function AppHeaderTools() { - const auth = useAuth() + const { logout, user, isAuthenticated, isLoading } = useAuth() + const username = isAuthenticated || isLoading ? user?.name : 'Anonymous' + const avatar = isAuthenticated || isLoading ? user?.picture : '/img/avatar.svg' const [isKebabDropdownOpen, setKebabDropdownOpen] = useState(false) const kebabDropdownItems = [ @@ -56,7 +58,11 @@ function AppHeaderTools() { const [isDropdownOpen, setDropdownOpen] = useState(false) const userDropdownItems = [ - auth.logout({ returnTo: window.location.origin })}> + logout({ returnTo: window.location.origin })} + > Logout , @@ -105,7 +111,7 @@ function AppHeaderTools() { isOpen={isDropdownOpen} toggle={ setDropdownOpen(!isDropdownOpen)}> - {auth?.user?.name ?? ( + {username ?? ( - {auth?.user?.picture ? ( - + {avatar ? ( + ) : ( )} -- cgit v1.2.3