diff --git a/.changeset/wicked-dryers-grow.md b/.changeset/wicked-dryers-grow.md new file mode 100644 index 0000000000..6c18ab559d --- /dev/null +++ b/.changeset/wicked-dryers-grow.md @@ -0,0 +1,5 @@ +--- +'@backstage/core-components': patch +--- + +SignInPage: move the initial invocation of `login` away from the render method diff --git a/packages/core-components/src/layout/SignInPage/SignInPage.tsx b/packages/core-components/src/layout/SignInPage/SignInPage.tsx index a7dc85c4e5..910fc6a7bf 100644 --- a/packages/core-components/src/layout/SignInPage/SignInPage.tsx +++ b/packages/core-components/src/layout/SignInPage/SignInPage.tsx @@ -22,6 +22,7 @@ import { } from '@backstage/core-plugin-api'; import { Button, Grid, Typography } from '@material-ui/core'; import React, { useState } from 'react'; +import { useMount } from 'react-use'; import { Progress } from '../../components/Progress'; import { Content } from '../Content/Content'; import { ContentHeader } from '../ContentHeader/ContentHeader'; @@ -93,7 +94,6 @@ export const SingleSignInPage = ({ const configApi = useApi(configApiRef); const [error, setError] = useState(); - const [loginCount, setLoginCount] = useState(0); // The SignIn component takes some time to decide whether the user is logged-in or not. // showLoginPage is used to prevent a glitch-like experience where the sign-in page is @@ -102,7 +102,6 @@ export const SingleSignInPage = ({ type LoginOpts = { checkExisting?: boolean; showPopup?: boolean }; const login = async ({ checkExisting, showPopup }: LoginOpts) => { - setLoginCount(prev => prev + 1); try { let identity: BackstageIdentity | undefined; if (checkExisting) { @@ -151,9 +150,8 @@ export const SingleSignInPage = ({ setShowLoginPage(true); } }; - if (loginCount === 0) { - login({ checkExisting: true }); - } + + useMount(() => login({ checkExisting: true })); return showLoginPage ? (