Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 46 additions & 24 deletions extensions/azurePublish/src/components/azureProvisionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
Stack,
Text,
} from 'office-ui-fabric-react';
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib/MessageBar';
import { JsonEditor } from '@bfc/code-editor';
import { SharedColors } from '@uifabric/fluent-theme';
import { ResourceGroup } from '@azure/arm-resources/esm/models';
Expand Down Expand Up @@ -279,6 +280,9 @@ export const AzureProvisionDialog: React.FC = () => {

const [formData, setFormData] = useState<ProvisionFormData>(getDefaultFormData(currentConfig, extensionState));

const [isLoading, setIsLoading] = useState(true);
const [loadingErrorMessage, setLoadingErrorMessage] = useState<string>();

// null = loading
const [loginErrorMsg, setLoginErrorMsg] = useState<string>('');

Expand Down Expand Up @@ -366,29 +370,6 @@ export const AzureProvisionDialog: React.FC = () => {
};
}, []);

const getTokenForTenant = (tenantId: string) => {
// set tenantId in cache.
setTenantId(tenantId);
getARMTokenForTenant(tenantId)
.then((token) => {
setToken(token);
const decoded = decodeToken(token);
setCurrentUser({
token: token,
email: decoded.upn,
name: decoded.name,
expiration: (decoded.exp || 0) * 1000, // convert to ms,
sessionExpired: false,
});
setLoginErrorMsg(undefined);
})
.catch((err) => {
setTenantId(undefined);
setCurrentUser(undefined);
setLoginErrorMsg(err.message || err.toString());
});
};

useEffect(() => {
setPage(PageTypes.ChooseAction);
// TODO: need to get the tenant id from the auth config when running as web app,
Expand All @@ -411,6 +392,12 @@ export const AzureProvisionDialog: React.FC = () => {
});
setPageAndTitle(PageTypes.ChooseAction);
setLoginErrorMsg(undefined);
} else {
setLoadingErrorMessage(
formatMessage(
'There was a problem with the authentication access token. Close this dialog and try again. To be prompted to provide the access token again, clear it from application local storage.'
)
);
}
} else {
getTenants().then((tenants) => {
Expand All @@ -427,8 +414,33 @@ export const AzureProvisionDialog: React.FC = () => {
}
});
}

setIsLoading(false);
}, []);

const getTokenForTenant = (tenantId: string) => {
// set tenantId in cache.
setTenantId(tenantId);
getARMTokenForTenant(tenantId)
.then((token) => {
setToken(token);
const decoded = decodeToken(token);
setCurrentUser({
token: token,
email: decoded.upn,
name: decoded.name,
expiration: (decoded.exp || 0) * 1000, // convert to ms,
sessionExpired: false,
});
setLoginErrorMsg(undefined);
})
.catch((err) => {
setTenantId(undefined);
setCurrentUser(undefined);
setLoginErrorMsg(err.message || err.toString());
});
};

useEffect(() => {
if (formData.tenantId) {
if (formData.tenantId !== currentConfig?.tenantId) {
Expand Down Expand Up @@ -1069,14 +1081,24 @@ export const AzureProvisionDialog: React.FC = () => {

// if we haven't loaded the token yet, show a loading spinner
// unless we need to select the tenant first
if (!token) {
if (isLoading) {
return (
<div style={{ height: '100vh' }}>
<LoadingSpinner />
</div>
);
}

if (loadingErrorMessage) {
return (
<div style={{ height: '100vh' }}>
<MessageBar isMultiline messageBarType={MessageBarType.error}>
{loadingErrorMessage}
</MessageBar>
</div>
);
}

return (
<Fragment>
<ProvisionHandoff
Expand Down