This is an automated email from the ASF dual-hosted git repository.

warren pushed a commit to branch cloud-service-be-cognito
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/cloud-service-be-cognito by 
this push:
     new 6f69774e1 feat(config-ui): hidden signout when token does not exist 
(#4942)
6f69774e1 is described below

commit 6f69774e1a40d216c6fb60eb824474ebc0bcb719
Author: 青湛 <[email protected]>
AuthorDate: Mon Apr 17 17:02:13 2023 +0800

    feat(config-ui): hidden signout when token does not exist (#4942)
---
 config-ui/src/layouts/base/base.tsx | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/config-ui/src/layouts/base/base.tsx 
b/config-ui/src/layouts/base/base.tsx
index 20044b0c4..5f546a458 100644
--- a/config-ui/src/layouts/base/base.tsx
+++ b/config-ui/src/layouts/base/base.tsx
@@ -41,6 +41,8 @@ export const BaseLayout = ({ children }: Props) => {
   const { pathname } = useLocation();
   const { version } = useVersion();
 
+  const token = window.localStorage.getItem('accessToken');
+
   const handlePushPath = (it: MenuItemType) => {
     if (!it.target) {
       history.push(it.path);
@@ -49,6 +51,11 @@ export const BaseLayout = ({ children }: Props) => {
     }
   };
 
+  const handleSignOut = () => {
+    localStorage.removeItem(`accessToken`);
+    history.push('/login');
+  };
+
   const getGrafanaUrl = () => {
     const suffix = '/d/lCO8w-pVk/homepage?orgId=1';
     const { protocol, hostname } = window.location;
@@ -131,10 +138,14 @@ export const BaseLayout = ({ children }: Props) => {
               <img src={SlackIcon} alt="slack" />
               <span>Slack</span>
             </a>
-            <Navbar.Divider />
-            <Button small intent={Intent.NONE} onClick={handleSignOut}>
-              Sign Out
-            </Button>
+            {token && (
+              <>
+                <Navbar.Divider />
+                <Button small intent={Intent.NONE} onClick={handleSignOut}>
+                  Sign Out
+                </Button>
+              </>
+            )}
           </Navbar.Group>
         </S.Header>
         <S.Inner>
@@ -144,10 +155,3 @@ export const BaseLayout = ({ children }: Props) => {
     </S.Wrapper>
   );
 };
-
-const handleSignOut = () => {
-  // Clear user authentication information (e.g. token)
-  localStorage.removeItem(`accessToken`);
-  // Redirect user to the login page
-  history.push('/login');
-};

Reply via email to