Skip to content

Commit

Permalink
Fix: Enable promptless logout (#1841)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElinorW authored Jun 21, 2022
1 parent 61fbbf4 commit 064fdd3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/app/services/actions/auth-action-creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export function signOut() {
authenticationWrapper.logOut();
} else {
authenticationWrapper.logOutPopUp();
dispatch(signOutSuccess(false));
}
dispatch(signOutSuccess(true));
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/app/services/reducers/query-runner-reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IAction } from '../../../types/action';
import { IGraphResponse } from '../../../types/query-response';
import {
CLEAR_RESPONSE,
LOGOUT_SUCCESS,
QUERY_GRAPH_RUNNING,
QUERY_GRAPH_SUCCESS,
VIEW_HISTORY_ITEM_SUCCESS
Expand All @@ -25,6 +26,8 @@ export function graphResponse(
return initialState;
case CLEAR_RESPONSE:
return initialState;
case LOGOUT_SUCCESS:
return initialState;
default:
return state;
}
Expand Down
4 changes: 3 additions & 1 deletion src/app/services/reducers/query-runner-status-reducers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IAction } from '../../../types/action';
import { CLEAR_QUERY_STATUS,
GET_CONSENT_ERROR, QUERY_GRAPH_RUNNING, QUERY_GRAPH_STATUS,
GET_CONSENT_ERROR, LOGOUT_SUCCESS, QUERY_GRAPH_RUNNING, QUERY_GRAPH_STATUS,
VIEW_HISTORY_ITEM_SUCCESS } from '../redux-constants';

export function queryRunnerStatus(state = {}, action: IAction): any {
Expand All @@ -15,6 +15,8 @@ export function queryRunnerStatus(state = {}, action: IAction): any {
return null;
case VIEW_HISTORY_ITEM_SUCCESS:
return null;
case LOGOUT_SUCCESS:
return null;
default:
return state;
}
Expand Down
14 changes: 10 additions & 4 deletions src/modules/authentication/AuthenticationWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,16 @@ export class AuthenticationWrapper implements IAuthenticationWrapper {
}
}

public logOut() {
this.deleteHomeAccountId();
msalApplication.logoutRedirect();
public async logOut() {
const homeAccountId = this.getHomeAccountId();
if( homeAccountId) {
const currentAccount = msalApplication.getAccountByHomeId(homeAccountId);
const logoutHint = currentAccount!.idTokenClaims?.login_hint;
await msalApplication.logoutPopup({ logoutHint });
} else {
this.deleteHomeAccountId();
await msalApplication.logoutRedirect();
}
}

public async logOutPopUp() {
Expand Down Expand Up @@ -161,7 +168,6 @@ export class AuthenticationWrapper implements IAuthenticationWrapper {
return result;
} catch (error: any) {
if (error instanceof InteractionRequiredAuthError || !this.getAccount()) {

return this.loginWithInteraction(silentRequest.scopes, sessionId);

} else if (signInAuthError(error)) {
Expand Down

0 comments on commit 064fdd3

Please sign in to comment.