From fe2650c4fde35da0edcd0d6ad2463d520e15e913 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Thu, 25 Jun 2020 18:52:13 +0200 Subject: [PATCH] Refactored logout --- package-lock.json | 12 ++++++------ package.json | 4 ++-- projects/common/src/fm/actions/app-common.actions.ts | 9 +++++++++ .../fm/components/user-menu/user-menu.component.ts | 2 +- projects/common/src/fm/effects/app-common.effects.ts | 10 +++++++++- .../common/src/fm/reducers/app-common.reducer.ts | 3 +++ 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3006d4e..ed7e524 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2692,14 +2692,14 @@ } }, "@farmmaps/common": { - "version": "0.0.1-prerelease.289", - "resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common/-/common-0.0.1-prerelease.289.tgz", - "integrity": "sha512-TlgNLEpagOtgC24X/olIrK+9ijLbh1gqLKEw4FgoyRV/T4iYBuZewfGvrPmoeKxY6lNdx2nIAhwOmOoRMcH5qQ==" + "version": "0.0.1-prerelease.300", + "resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common/-/common-0.0.1-prerelease.300.tgz", + "integrity": "sha512-76f+K6ZWQki9HL7cYmiQt+/Bkprfb1+y6C0vSPN3EpRSG7DSRLTdjk/cJoy6VVThS38YADUQom8Bvw4arNXhZw==" }, "@farmmaps/common-map": { - "version": "0.0.1-prerelease.289", - "resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common-map/-/common-map-0.0.1-prerelease.289.tgz", - "integrity": "sha512-HOECDkP7xwBQqbGx2WmaKgtyalwgcw/7K4CW5eTMT0kSJXc+2JJbCDcQlso5a1DwzaF24bzpR3L1sEGJiPof4w==" + "version": "0.0.1-prerelease.300", + "resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common-map/-/common-map-0.0.1-prerelease.300.tgz", + "integrity": "sha512-PMgAgRj9wvUEaSCcMyNcyAovViu05wwh8b6taSSWLs7G6eS2RAToIlBrYIXsPRbcC1cyV58W10e5UrbNHeECvw==" }, "@istanbuljs/schema": { "version": "0.1.2", diff --git a/package.json b/package.json index a0334da..261c7ef 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "@angular/platform-browser": "~9.1.0", "@angular/platform-browser-dynamic": "~9.1.0", "@angular/router": "~9.1.0", - "@farmmaps/common": ">=0.0.1-prerelease.289 <0.0.1", - "@farmmaps/common-map": ">=0.0.1-prerelease.289 <0.0.1", + "@farmmaps/common": ">=0.0.1-prerelease.300 <0.0.1", + "@farmmaps/common-map": ">=0.0.1-prerelease.300 <0.0.1", "@microsoft/signalr": "^3.1.3", "@ng-bootstrap/ng-bootstrap": "^6.0", "@ngrx/effects": "^9.0", diff --git a/projects/common/src/fm/actions/app-common.actions.ts b/projects/common/src/fm/actions/app-common.actions.ts index bee18cd..ee26994 100644 --- a/projects/common/src/fm/actions/app-common.actions.ts +++ b/projects/common/src/fm/actions/app-common.actions.ts @@ -18,6 +18,7 @@ export const INITROOTSUCCESS = '[Explorer] InitRootSuccess'; export const OPENMODAL = '[AppCommon] OpenModal'; export const CLOSEMODAL = '[AppCommon] CloseModal'; export const LOGIN = '[AppCommon] Login'; +export const LOGOUT = '[AppCommon] Logout'; export const ESCAPE = '[AppCommon] Escape'; export const LOADITEMTYPES = '[AppCommon] LoadItemTypes'; @@ -116,6 +117,12 @@ export class Login implements Action { constructor(public url: string) { } } +export class Logout implements Action { + readonly type = LOGOUT; + + constructor() { } +} + export class Escape implements Action { readonly type = ESCAPE; @@ -247,6 +254,7 @@ export type Actions = OpenModal | InitRootSuccess | CloseModal | Login + | Logout | ItemChangedEvent | ItemAddedEvent | ItemDeletedEvent @@ -273,3 +281,4 @@ export type Actions = OpenModal | InitUserPackagesSuccess | ToggleAccountMenu; + diff --git a/projects/common/src/fm/components/user-menu/user-menu.component.ts b/projects/common/src/fm/components/user-menu/user-menu.component.ts index 99d7d92..8e3f826 100644 --- a/projects/common/src/fm/components/user-menu/user-menu.component.ts +++ b/projects/common/src/fm/components/user-menu/user-menu.component.ts @@ -26,7 +26,7 @@ export class UserMenuComponent implements OnInit { logout(event:MouseEvent) { event.preventDefault(); - this.oauthService.logOut(); + this.store.dispatch(new appActions.Logout()); } diff --git a/projects/common/src/fm/effects/app-common.effects.ts b/projects/common/src/fm/effects/app-common.effects.ts index fdeb82f..7a4406b 100644 --- a/projects/common/src/fm/effects/app-common.effects.ts +++ b/projects/common/src/fm/effects/app-common.effects.ts @@ -25,10 +25,18 @@ export class AppCommonEffects { withLatestFrom(this.store$.select(appCommonReducers.selectGetInitialized)), mergeMap(([action, initialized]) => { var a = (action as appCommonActions.Login); - this.oauthService$.initCodeFlow(a.url); + this.oauthService$.initCodeFlow(a.url,{"prompt":"login"}); return []; })); + @Effect({ dispatch: false }) + logout$: Observable = this.actions$.pipe( + ofType(appCommonActions.LOGOUT), + mergeMap((action) => { + this.oauthService$.logOut(true); + return []; + })); + @Effect() loadItemTypes$: Observable = this.actions$.pipe( ofType(appCommonActions.LOADITEMTYPES), diff --git a/projects/common/src/fm/reducers/app-common.reducer.ts b/projects/common/src/fm/reducers/app-common.reducer.ts index 3ad64ca..d377286 100644 --- a/projects/common/src/fm/reducers/app-common.reducer.ts +++ b/projects/common/src/fm/reducers/app-common.reducer.ts @@ -106,6 +106,9 @@ export function reducer(state = initialState, action: appCommonActions.Actions ) return tassign(state,{userPackages:packages}); } + case appCommonActions.LOGOUT:{ + return tassign(state,{user:null}); + } default: { return state; }