Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite spinning when login fails #492

Merged
merged 5 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
33 changes: 25 additions & 8 deletions src/app/views/authentication/Authentication.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Icon, Label, Spinner, SpinnerSize, styled } from 'office-ui-fabric-react';
import { Icon, Label, MessageBarType, Spinner, SpinnerSize, styled } from 'office-ui-fabric-react';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';
Expand All @@ -7,6 +7,7 @@ import { FormattedMessage } from 'react-intl';
import { IAuthenticationProps } from '../../../types/authentication';
import { Mode } from '../../../types/enums';
import * as authActionCreators from '../../services/actions/auth-action-creators';
import * as queryStatusActionCreators from '../../services/actions/query-status-action-creator';
import { logIn } from '../../services/graph-client/msal-service';
import { classNames } from '../classnames';
import { showSignInButtonOrProfile } from './auth-util-components';
Expand All @@ -19,6 +20,9 @@ export class Authentication extends Component<IAuthenticationProps, { loginInPro
}

public signIn = async (): Promise<void> => {
const {
intl: { messages },
}: any = this.props;
this.setState({ loginInProgress: true });

const { mscc } = (window as any);
Expand All @@ -27,15 +31,25 @@ export class Authentication extends Component<IAuthenticationProps, { loginInPro
mscc.setConsent();
}

const authResponse = await logIn();
if (authResponse) {
try {
const authResponse = await logIn();
if (authResponse) {
this.setState({ loginInProgress: false });

this.props.actions!.signIn(authResponse.accessToken);
this.props.actions!.storeScopes(authResponse.scopes);
}
} catch (error) {
const { errorCode } = error;
this.props.actions!.setQueryResponseStatus({
ok: false,
statusText: messages['Authentication Failed'],
status: errorCode.replace('_', ' '),
messageType: MessageBarType.error
});
this.setState({ loginInProgress: false });

this.props.actions!.signIn(authResponse.accessToken);
this.props.actions!.storeScopes(authResponse.scopes);
}

this.setState({ loginInProgress: false });
};

public render() {
Expand Down Expand Up @@ -94,7 +108,10 @@ function mapStateToProps(state: any) {

function mapDispatchToProps(dispatch: Dispatch): object {
return {
actions: bindActionCreators(authActionCreators, dispatch)
actions: bindActionCreators({
...authActionCreators,
...queryStatusActionCreators},
dispatch)
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/messages/GE.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,6 @@
"viewing a cached set": "You are viewing a cached set of samples because of a network connection failure.",
"see more queries":"See more queries in the",
"Microsoft Graph API Reference docs": "Microsoft Graph API Reference docs.",
"Fetching permissions": "Fetching permissions"
"Fetching permissions": "Fetching permissions",
"Authentication failed": "Authentication failed"
}
4 changes: 4 additions & 0 deletions src/types/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { Mode } from './enums';

export interface IAuthenticationProps {
theme?: ITheme;
intl: {
message: object;
};
styles?: object;
actions?: {
signIn: Function;
storeScopes: Function;
setQueryResponseStatus: Function;
};
tokenPresent: boolean;
mobileScreen: boolean;
Expand Down