Skip to content

Commit

Permalink
feat!: allow AAD errors to bubble
Browse files Browse the repository at this point in the history
BREAKING CHANGE: stop silencing errors from aad
  • Loading branch information
vegardok committed Jun 23, 2021
1 parent c1924b3 commit 00dacb4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
21 changes: 6 additions & 15 deletions packages/core/src/authFlows/aad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,11 @@ export class AzureAD {
): Promise<AccountInfo | void> {
const { type, requestParams } = signInType;
if (type === AZURE_AUTH_POPUP) {
try {
const { account } = await this.msalApplication.loginPopup(
this.getLoginPopupRequest(requestParams)
);

return this.handleAuthAccountResult(account);
} catch (error) {
console.error(error);
}
const { account } = await this.msalApplication.loginPopup(
this.getLoginPopupRequest(requestParams)
);

return this.handleAuthAccountResult(account);
} else {
await this.msalApplication.loginRedirect(
this.getLoginRedirectRequest(requestParams)
Expand Down Expand Up @@ -241,12 +237,7 @@ export class AzureAD {
}

private async handleAuthRedirect(): Promise<AccountInfo | null> {
let redirectResult;
try {
redirectResult = await this.msalApplication.handleRedirectPromise();
} catch (e) {
console.error('Error while handling auth redirect', e);
}
const redirectResult = await this.msalApplication.handleRedirectPromise();

return redirectResult && redirectResult.account
? redirectResult.account
Expand Down
12 changes: 11 additions & 1 deletion samples/react/authentication-aad/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function App() {
const [assets, setAssets] = useState([]);
const [isInit, setIsInit] = useState(false);
const [isSignedIn, setIsSignedIn] = useState(false);
const [error, setError] = useState(undefined);

const fetchRootAssets = async () => {
if (client === null) return;
Expand All @@ -44,7 +45,10 @@ function App() {
const authenticate = async () => {
if (client === null) return;

const result = await client.authenticate();
const result = await client.authenticate().catch(e => {
setError(e.message);
throw e;
});

if (result) {
client.setProject(project);
Expand Down Expand Up @@ -79,6 +83,12 @@ function App() {
<button disabled={!isInit || isSignedIn} onClick={authenticate}><h1>Authenticate</h1></button>
<button disabled={!isInit || !isSignedIn} onClick={fetchRootAssets}><h1>Click here to fetch assets from Cognite</h1></button>
{assets && renderAssetsInTable(assets)}
{error && (
<>
<h3>Error</h3>
<pre>{error}</pre>
</>
)}
</div>
);
}
Expand Down

0 comments on commit 00dacb4

Please sign in to comment.