Skip to content

Commit

Permalink
fix optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
tihuan committed Oct 7, 2020
1 parent c30b8a9 commit 35e5786
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions client/src/components/leftSidebar/topLeftLogoAndTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ class LeftSideBar extends React.Component {
userinfo,
}}
/>
{!userinfo.is_authenticated ? (
{!userinfo.is_authenticated && (
<AuthButtons auth={auth} userinfo={userinfo} />
) : null}
)}
</div>
</div>
);
Expand Down
12 changes: 6 additions & 6 deletions client/src/components/menubar/authButtons.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable camelcase -- Allowing snake_case from BE */
import React, { useState } from "react";
import {
AnchorButton,
Expand All @@ -24,6 +23,8 @@ const Auth = React.memo((props) => {

const { auth, userinfo } = props;

const isAuthenticated = userinfo && userinfo.is_authenticated;

if (shouldShowAuth()) return null;

const AuthButton = () => {
Expand All @@ -32,9 +33,9 @@ const Auth = React.memo((props) => {
type="button"
data-testid="auth-button"
disabled={false}
href={!userinfo?.is_authenticated ? auth.login : auth.logout}
href={isAuthenticated ? auth.logout : auth.login}
>
{!userinfo?.is_authenticated ? "Log In" : "Log Out"}
{isAuthenticated ? "Log Out" : "Log In"}
</AnchorButton>
);
};
Expand Down Expand Up @@ -62,13 +63,13 @@ const Auth = React.memo((props) => {
);

function shouldShowAuth() {
return auth?.requires_client_login;
return auth && auth.requires_client_login;
}

function shouldShowPrompt() {
if (storageGet(KEYS.LOGIN_PROMPT) === LOGIN_PROMPT_OFF) return false;

return shouldShowAuth && !userinfo?.is_authenticated;
return shouldShowAuth && !isAuthenticated;
}
});

Expand Down Expand Up @@ -119,4 +120,3 @@ function PopoverContent({ setIsPromptOpen }) {
}

export default Auth;
/* eslint-enable camelcase -- BE */

0 comments on commit 35e5786

Please sign in to comment.