From 9e793d3f8dea8274582359a4fab01080a1d5731e Mon Sep 17 00:00:00 2001 From: Himanshu Mishra Date: Thu, 20 May 2021 11:00:41 +0200 Subject: [PATCH] auth(signinpage): handle case when auto is set to false A check for existing user session should still be made. Signed-off-by: Himanshu Mishra --- .../core/src/layout/SignInPage/SignInPage.tsx | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/core/src/layout/SignInPage/SignInPage.tsx b/packages/core/src/layout/SignInPage/SignInPage.tsx index 92041f9a0f..6a8dcf454e 100644 --- a/packages/core/src/layout/SignInPage/SignInPage.tsx +++ b/packages/core/src/layout/SignInPage/SignInPage.tsx @@ -81,13 +81,15 @@ export const MultiSignInPage = ({ export const SingleSignInPage = ({ onResult, provider, - auto = true, + auto, }: SingleSignInPageProps) => { const classes = useStyles(); const authApi = useApi(provider.apiRef); const configApi = useApi(configApiRef); - const [retry, setRetry] = useState<{} | boolean | undefined>(auto); + const [autoShowPopup, setAutoShowPopup] = useState(auto ?? false); + // Defaults to true so that an initial check for existing user session is made + const [retry, setRetry] = useState<{} | boolean | undefined>(true); const [error, setError] = useState(); // The SignIn component takes some time to decide whether the user is logged-in or not. @@ -105,12 +107,19 @@ export const SingleSignInPage = ({ }); // If no session exists, show the sign-in page - if (!identity) { + if (!identity && autoShowPopup) { + // Unless auto is set to true, this step should not happen. + // When user intentionally clicks the Sign In button, autoShowPopup is set to true identity = await authApi.getBackstageIdentity({ instantPopup: true, }); } + if (!identity) { + setShowLoginPage(true); + return; + } + const profile = await authApi.getProfile(); onResult({ userId: identity!.id, @@ -132,7 +141,7 @@ export const SingleSignInPage = ({ if (retry) { login(); } - }, [onResult, authApi, retry]); + }, [onResult, authApi, retry, autoShowPopup]); return showLoginPage ? ( @@ -153,7 +162,10 @@ export const SingleSignInPage = ({