@daffodil/auth 0.59.2 → 0.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/driver/in-memory/package.json +1 -1
- package/driver/magento/package.json +1 -1
- package/driver/package.json +1 -1
- package/driver/testing/package.json +1 -1
- package/esm2020/state/actions/auth.actions.mjs +11 -1
- package/esm2020/state/auth-state.module.mjs +5 -4
- package/esm2020/state/effects/auth.effects.mjs +16 -5
- package/esm2020/state/effects/login.effects.mjs +11 -15
- package/esm2020/state/facades/auth/facade.mjs +5 -5
- package/esm2020/state/facades/login/facade.mjs +5 -5
- package/esm2020/state/facades/register/facade.mjs +5 -5
- package/esm2020/state/facades/reset-password/facade.mjs +5 -5
- package/esm2020/state/injection-tokens/public_api.mjs +2 -0
- package/esm2020/state/injection-tokens/unauthenticated/hook.token.mjs +15 -0
- package/esm2020/state/injection-tokens/unauthenticated/hooks.token.mjs +29 -0
- package/esm2020/state/injection-tokens/unauthenticated/public_api.mjs +2 -0
- package/esm2020/state/public_api.mjs +2 -1
- package/esm2020/state/reducers/auth/auth-initial-state.mjs +3 -3
- package/esm2020/state/reducers/auth/auth-reducer-state.interface.mjs +1 -1
- package/esm2020/state/reducers/auth/auth.reducer.mjs +6 -16
- package/esm2020/state/reducers/login/login-initial-state.mjs +3 -5
- package/esm2020/state/reducers/login/login-reducer-state.interface.mjs +1 -1
- package/esm2020/state/reducers/login/login.reducer.mjs +5 -15
- package/esm2020/state/reducers/public_api.mjs +2 -1
- package/esm2020/state/reducers/register/register-initial-state.mjs +3 -5
- package/esm2020/state/reducers/register/register-reducer-state.interface.mjs +1 -1
- package/esm2020/state/reducers/register/register.reducer.mjs +5 -15
- package/esm2020/state/reducers/reset-password/initial-state.mjs +3 -3
- package/esm2020/state/reducers/reset-password/reducer.mjs +5 -15
- package/esm2020/state/reducers/reset-password/state.interface.mjs +1 -1
- package/esm2020/state/reducers/token/extra.token.mjs +27 -0
- package/esm2020/state/reducers/token/public_api.mjs +2 -0
- package/esm2020/state/reducers/token/reducers.token.mjs +18 -0
- package/esm2020/state/selectors/auth/auth.selector.mjs +4 -6
- package/esm2020/state/selectors/auth-all.selector.mjs +9 -9
- package/esm2020/state/selectors/login/login.selector.mjs +4 -6
- package/esm2020/state/selectors/public_api.mjs +5 -1
- package/esm2020/state/selectors/register/register.selector.mjs +4 -6
- package/esm2020/state/selectors/reset-password/selector.mjs +4 -6
- package/fesm2015/daffodil-auth-state.mjs +158 -99
- package/fesm2015/daffodil-auth-state.mjs.map +1 -1
- package/fesm2020/daffodil-auth-state.mjs +159 -126
- package/fesm2020/daffodil-auth-state.mjs.map +1 -1
- package/package.json +1 -1
- package/routing/package.json +1 -1
- package/state/actions/auth.actions.d.ts +5 -1
- package/state/effects/auth.effects.d.ts +4 -2
- package/state/effects/login.effects.d.ts +3 -6
- package/state/facades/auth/facade.d.ts +2 -2
- package/state/facades/login/facade.d.ts +2 -2
- package/state/facades/register/facade.d.ts +2 -2
- package/state/facades/reset-password/facade.d.ts +2 -2
- package/state/injection-tokens/public_api.d.ts +1 -0
- package/state/injection-tokens/unauthenticated/hook.token.d.ts +8 -0
- package/state/injection-tokens/unauthenticated/hooks.token.d.ts +22 -0
- package/state/injection-tokens/unauthenticated/public_api.d.ts +1 -0
- package/state/package.json +1 -1
- package/state/public_api.d.ts +1 -0
- package/state/reducers/auth/auth-reducer-state.interface.d.ts +2 -4
- package/state/reducers/login/login-reducer-state.interface.d.ts +2 -5
- package/state/reducers/login/login.reducer.d.ts +1 -1
- package/state/reducers/public_api.d.ts +1 -0
- package/state/reducers/register/register-reducer-state.interface.d.ts +2 -5
- package/state/reducers/register/register.reducer.d.ts +1 -1
- package/state/reducers/reset-password/state.interface.d.ts +2 -4
- package/state/reducers/token/extra.token.d.ts +22 -0
- package/state/reducers/token/public_api.d.ts +1 -0
- package/state/reducers/token/reducers.token.d.ts +10 -0
- package/state/selectors/auth/auth.selector.d.ts +6 -8
- package/state/selectors/login/login.selector.d.ts +5 -7
- package/state/selectors/public_api.d.ts +4 -0
- package/state/selectors/register/register.selector.d.ts +5 -8
- package/state/selectors/reset-password/selector.d.ts +6 -8
- package/state/testing/package.json +1 -1
- package/testing/package.json +1 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createFeatureSelector, createSelector, select, StoreModule } from '@ngrx/store';
|
|
1
|
+
import { daffOperationInitialState, daffOperationFailed, daffCompleteOperation, daffStartResolution, daffStartMutation, daffOperationStateSelectorFactory, daffComposeReducers } from '@daffodil/core/state';
|
|
3
2
|
import * as i0 from '@angular/core';
|
|
4
|
-
import { Injectable,
|
|
3
|
+
import { InjectionToken, Injectable, inject, Inject, NgModule } from '@angular/core';
|
|
4
|
+
import * as i1 from '@ngrx/store';
|
|
5
|
+
import { createFeatureSelector, createSelector, select, combineReducers, StoreModule } from '@ngrx/store';
|
|
5
6
|
import * as i1$1 from '@ngrx/effects';
|
|
6
7
|
import { createEffect, ofType, EffectsModule } from '@ngrx/effects';
|
|
7
8
|
import { of, EMPTY, iif, defer } from 'rxjs';
|
|
@@ -15,6 +16,7 @@ import { DaffLoginDriver, DaffRegisterDriver, DaffResetPasswordDriver } from '@d
|
|
|
15
16
|
|
|
16
17
|
var DaffAuthActionTypes;
|
|
17
18
|
(function (DaffAuthActionTypes) {
|
|
19
|
+
DaffAuthActionTypes["ResetToUnauthenticatedAction"] = "[@daffodil/auth] Reset To Unauthenticated Action";
|
|
18
20
|
DaffAuthActionTypes["AuthStorageFailureAction"] = "[@daffodil/auth] Auth Storage Failure Action";
|
|
19
21
|
DaffAuthActionTypes["AuthGuardLogoutAction"] = "[@daffodil/auth] Auth Guard Logout Action";
|
|
20
22
|
DaffAuthActionTypes["AuthServerSideAction"] = "[@daffodil/auth] Auth Server Side Action";
|
|
@@ -22,6 +24,15 @@ var DaffAuthActionTypes;
|
|
|
22
24
|
DaffAuthActionTypes["AuthCheckSuccessAction"] = "[@daffodil/auth] Auth Check Success Action";
|
|
23
25
|
DaffAuthActionTypes["AuthCheckFailureAction"] = "[@daffodil/auth] Auth Check Failure Action";
|
|
24
26
|
})(DaffAuthActionTypes || (DaffAuthActionTypes = {}));
|
|
27
|
+
/*
|
|
28
|
+
* An action triggered when the authenicated status of the user is invalidated for some reason.
|
|
29
|
+
* That reason could be a logout, auth token check failure, or an unauthorized error.
|
|
30
|
+
*/
|
|
31
|
+
class DaffAuthResetToUnauthenticated {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.type = DaffAuthActionTypes.ResetToUnauthenticatedAction;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
25
36
|
/*
|
|
26
37
|
* An action triggered upon a failed auth storage operation.
|
|
27
38
|
*/
|
|
@@ -271,24 +282,20 @@ class DaffResetPasswordLanding {
|
|
|
271
282
|
}
|
|
272
283
|
}
|
|
273
284
|
|
|
274
|
-
const daffAuthInitialState = {
|
|
275
|
-
loading: false,
|
|
276
|
-
errors: [],
|
|
277
|
-
loggedIn: false,
|
|
278
|
-
};
|
|
285
|
+
const daffAuthInitialState = Object.assign(Object.assign({}, daffOperationInitialState), { loggedIn: false });
|
|
279
286
|
|
|
280
287
|
function daffAuthReducer(state = daffAuthInitialState, action) {
|
|
281
288
|
switch (action.type) {
|
|
282
289
|
case DaffAuthActionTypes.AuthCheckAction:
|
|
283
|
-
return
|
|
290
|
+
return daffStartResolution(state);
|
|
284
291
|
case DaffAuthActionTypes.AuthCheckSuccessAction:
|
|
285
|
-
return Object.assign(Object.assign({}, state), { loggedIn: true
|
|
292
|
+
return Object.assign(Object.assign({}, daffCompleteOperation(state)), { loggedIn: true });
|
|
286
293
|
case DaffAuthActionTypes.AuthCheckFailureAction:
|
|
287
294
|
case DaffAuthActionTypes.AuthGuardLogoutAction:
|
|
288
|
-
return Object.assign(Object.assign({}, state), { loggedIn: false
|
|
295
|
+
return Object.assign(Object.assign({}, daffOperationFailed([action.errorMessage], state)), { loggedIn: false });
|
|
289
296
|
case DaffAuthActionTypes.AuthServerSideAction:
|
|
290
297
|
case DaffAuthActionTypes.AuthStorageFailureAction:
|
|
291
|
-
return
|
|
298
|
+
return daffOperationFailed([action.errorMessage], state);
|
|
292
299
|
case DaffAuthLoginActionTypes.LoginSuccessAction:
|
|
293
300
|
return Object.assign(Object.assign({}, state), { loggedIn: true });
|
|
294
301
|
case DaffAuthRegisterActionTypes.RegisterSuccessAction:
|
|
@@ -301,62 +308,52 @@ function daffAuthReducer(state = daffAuthInitialState, action) {
|
|
|
301
308
|
}
|
|
302
309
|
}
|
|
303
310
|
|
|
304
|
-
const daffAuthLoginInitialState =
|
|
305
|
-
loading: false,
|
|
306
|
-
errors: [],
|
|
307
|
-
};
|
|
311
|
+
const daffAuthLoginInitialState = daffOperationInitialState;
|
|
308
312
|
|
|
309
313
|
function daffAuthLoginReducer(state = daffAuthLoginInitialState, action) {
|
|
310
314
|
switch (action.type) {
|
|
311
315
|
case DaffAuthLoginActionTypes.LoginAction:
|
|
312
316
|
case DaffAuthLoginActionTypes.LogoutAction:
|
|
313
|
-
return
|
|
317
|
+
return daffStartMutation(state);
|
|
314
318
|
case DaffAuthLoginActionTypes.LoginSuccessAction:
|
|
315
319
|
case DaffAuthLoginActionTypes.LogoutSuccessAction:
|
|
316
|
-
return
|
|
320
|
+
return daffCompleteOperation(state);
|
|
317
321
|
case DaffAuthLoginActionTypes.LoginFailureAction:
|
|
318
322
|
case DaffAuthLoginActionTypes.LogoutFailureAction:
|
|
319
|
-
return
|
|
323
|
+
return daffOperationFailed([action.errorMessage], state);
|
|
320
324
|
default:
|
|
321
325
|
return state;
|
|
322
326
|
}
|
|
323
327
|
}
|
|
324
328
|
|
|
325
|
-
const daffAuthRegisterInitialState =
|
|
326
|
-
loading: false,
|
|
327
|
-
errors: [],
|
|
328
|
-
};
|
|
329
|
+
const daffAuthRegisterInitialState = daffOperationInitialState;
|
|
329
330
|
|
|
330
331
|
function daffAuthRegisterReducer(state = daffAuthRegisterInitialState, action) {
|
|
331
332
|
switch (action.type) {
|
|
332
333
|
case DaffAuthRegisterActionTypes.RegisterAction:
|
|
333
|
-
return
|
|
334
|
+
return daffStartMutation(state);
|
|
334
335
|
case DaffAuthRegisterActionTypes.RegisterSuccessAction:
|
|
335
|
-
return
|
|
336
|
+
return daffCompleteOperation(state);
|
|
336
337
|
case DaffAuthRegisterActionTypes.RegisterFailureAction:
|
|
337
|
-
return
|
|
338
|
+
return daffOperationFailed([action.errorMessage], state);
|
|
338
339
|
default:
|
|
339
340
|
return state;
|
|
340
341
|
}
|
|
341
342
|
}
|
|
342
343
|
|
|
343
|
-
const daffAuthResetPasswordInitialState = {
|
|
344
|
-
loading: false,
|
|
345
|
-
errors: [],
|
|
346
|
-
token: null,
|
|
347
|
-
};
|
|
344
|
+
const daffAuthResetPasswordInitialState = Object.assign(Object.assign({}, daffOperationInitialState), { token: null });
|
|
348
345
|
|
|
349
346
|
function daffAuthResetPasswordReducer(state = daffAuthResetPasswordInitialState, action) {
|
|
350
347
|
switch (action.type) {
|
|
351
348
|
case DaffAuthResetPasswordActionTypes.ResetPasswordAction:
|
|
352
349
|
case DaffAuthResetPasswordActionTypes.SendResetEmailAction:
|
|
353
|
-
return
|
|
350
|
+
return daffStartMutation(state);
|
|
354
351
|
case DaffAuthResetPasswordActionTypes.ResetPasswordSuccessAction:
|
|
355
352
|
case DaffAuthResetPasswordActionTypes.SendResetEmailSuccessAction:
|
|
356
|
-
return
|
|
353
|
+
return daffCompleteOperation(state);
|
|
357
354
|
case DaffAuthResetPasswordActionTypes.ResetPasswordFailureAction:
|
|
358
355
|
case DaffAuthResetPasswordActionTypes.SendResetEmailFailureAction:
|
|
359
|
-
return
|
|
356
|
+
return daffOperationFailed([action.errorMessage], state);
|
|
360
357
|
case DaffAuthResetPasswordActionTypes.ResetPasswordLandingAction:
|
|
361
358
|
return Object.assign(Object.assign({}, state), { token: action.token });
|
|
362
359
|
default:
|
|
@@ -364,6 +361,32 @@ function daffAuthResetPasswordReducer(state = daffAuthResetPasswordInitialState,
|
|
|
364
361
|
}
|
|
365
362
|
}
|
|
366
363
|
|
|
364
|
+
/**
|
|
365
|
+
* A token to hold the injectable extra reducers.
|
|
366
|
+
*
|
|
367
|
+
* Prefer using {@link daffAuthProvideExtraReducers}.
|
|
368
|
+
*/
|
|
369
|
+
const DAFF_AUTH_EXTRA_REDUCERS = new InjectionToken('DAFF_AUTH_EXTRA_REDUCERS', { factory: () => [] });
|
|
370
|
+
/**
|
|
371
|
+
* Provides additional reducers that run after the standard Daffodil auth reducers.
|
|
372
|
+
*
|
|
373
|
+
* ```ts
|
|
374
|
+
* providers: [
|
|
375
|
+
* ...daffAuthProvideExtraReducers(
|
|
376
|
+
* myReducer1,
|
|
377
|
+
* myReducer2
|
|
378
|
+
* )
|
|
379
|
+
* ]
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
function daffAuthProvideExtraReducers(...reducers) {
|
|
383
|
+
return reducers.map(reducer => ({
|
|
384
|
+
provide: DAFF_AUTH_EXTRA_REDUCERS,
|
|
385
|
+
useValue: reducer,
|
|
386
|
+
multi: true,
|
|
387
|
+
}));
|
|
388
|
+
}
|
|
389
|
+
|
|
367
390
|
const DAFF_AUTH_STORE_FEATURE_KEY = 'daffAuth';
|
|
368
391
|
|
|
369
392
|
const daffAuthReducers = {
|
|
@@ -383,71 +406,47 @@ const getDaffAuthFeatureStateSelector = (() => {
|
|
|
383
406
|
|
|
384
407
|
const createAuthSelectors = () => {
|
|
385
408
|
const selectAuthState = createSelector(getDaffAuthFeatureStateSelector(), state => state.auth);
|
|
386
|
-
const selectAuthLoading = createSelector(selectAuthState, state => state.loading);
|
|
387
|
-
const selectAuthErrors = createSelector(selectAuthState, state => state.errors);
|
|
388
409
|
const selectAuthLoggedIn = createSelector(selectAuthState, state => state.loggedIn);
|
|
389
|
-
return {
|
|
390
|
-
|
|
391
|
-
selectAuthLoading,
|
|
392
|
-
selectAuthErrors,
|
|
393
|
-
selectAuthLoggedIn,
|
|
394
|
-
};
|
|
410
|
+
return Object.assign(Object.assign({}, daffOperationStateSelectorFactory(selectAuthState)), { selectAuthState,
|
|
411
|
+
selectAuthLoggedIn });
|
|
395
412
|
};
|
|
396
|
-
const
|
|
413
|
+
const daffAuthSelectorFactory = (() => {
|
|
397
414
|
let cache;
|
|
398
415
|
return () => cache = cache || createAuthSelectors();
|
|
399
416
|
})();
|
|
400
417
|
|
|
401
418
|
const createLoginSelectors = () => {
|
|
402
419
|
const selectAuthLoginState = createSelector(getDaffAuthFeatureStateSelector(), state => state.login);
|
|
403
|
-
|
|
404
|
-
const selectAuthLoginErrors = createSelector(selectAuthLoginState, state => state.errors);
|
|
405
|
-
return {
|
|
406
|
-
selectAuthLoginState,
|
|
407
|
-
selectAuthLoginLoading,
|
|
408
|
-
selectAuthLoginErrors,
|
|
409
|
-
};
|
|
420
|
+
return Object.assign(Object.assign({}, daffOperationStateSelectorFactory(selectAuthLoginState)), { selectAuthLoginState });
|
|
410
421
|
};
|
|
411
|
-
const
|
|
422
|
+
const daffAuthLoginSelectorFactory = (() => {
|
|
412
423
|
let cache;
|
|
413
424
|
return () => cache = cache || createLoginSelectors();
|
|
414
425
|
})();
|
|
415
426
|
|
|
416
427
|
const createRegisterSelectors = () => {
|
|
417
428
|
const selectAuthRegisterState = createSelector(getDaffAuthFeatureStateSelector(), state => state.register);
|
|
418
|
-
|
|
419
|
-
const selectAuthRegisterErrors = createSelector(selectAuthRegisterState, state => state.errors);
|
|
420
|
-
return {
|
|
421
|
-
selectAuthRegisterState,
|
|
422
|
-
selectAuthRegisterLoading,
|
|
423
|
-
selectAuthRegisterErrors,
|
|
424
|
-
};
|
|
429
|
+
return Object.assign(Object.assign({}, daffOperationStateSelectorFactory(selectAuthRegisterState)), { selectAuthRegisterState });
|
|
425
430
|
};
|
|
426
|
-
const
|
|
431
|
+
const daffAuthRegisterSelectorFactory = (() => {
|
|
427
432
|
let cache;
|
|
428
433
|
return () => cache = cache || createRegisterSelectors();
|
|
429
434
|
})();
|
|
430
435
|
|
|
431
436
|
const createResetPasswordSelectors = () => {
|
|
432
437
|
const selectAuthResetPasswordState = createSelector(getDaffAuthFeatureStateSelector(), state => state.resetPassword);
|
|
433
|
-
const selectAuthResetPasswordLoading = createSelector(selectAuthResetPasswordState, state => state.loading);
|
|
434
|
-
const selectAuthResetPasswordErrors = createSelector(selectAuthResetPasswordState, state => state.errors);
|
|
435
438
|
const selectAuthResetPasswordToken = createSelector(selectAuthResetPasswordState, state => state.token);
|
|
436
|
-
return {
|
|
437
|
-
|
|
438
|
-
selectAuthResetPasswordLoading,
|
|
439
|
-
selectAuthResetPasswordErrors,
|
|
440
|
-
selectAuthResetPasswordToken,
|
|
441
|
-
};
|
|
439
|
+
return Object.assign(Object.assign({}, daffOperationStateSelectorFactory(selectAuthResetPasswordState)), { selectAuthResetPasswordState,
|
|
440
|
+
selectAuthResetPasswordToken });
|
|
442
441
|
};
|
|
443
|
-
const
|
|
442
|
+
const daffAuthResetPasswordSelectorFactory = (() => {
|
|
444
443
|
let cache;
|
|
445
444
|
return () => cache = cache || createResetPasswordSelectors();
|
|
446
445
|
})();
|
|
447
446
|
|
|
448
447
|
const getDaffAuthSelectors = (() => {
|
|
449
448
|
let cache;
|
|
450
|
-
return () => cache = cache || Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},
|
|
449
|
+
return () => cache = cache || Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, daffAuthSelectorFactory()), daffAuthLoginSelectorFactory()), daffAuthRegisterSelectorFactory()), daffAuthResetPasswordSelectorFactory()), { selectAuthFeatureState: getDaffAuthFeatureStateSelector() });
|
|
451
450
|
})();
|
|
452
451
|
|
|
453
452
|
/**
|
|
@@ -456,9 +455,9 @@ const getDaffAuthSelectors = (() => {
|
|
|
456
455
|
class DaffAuthFacade {
|
|
457
456
|
constructor(store) {
|
|
458
457
|
this.store = store;
|
|
459
|
-
const {
|
|
460
|
-
this.loading$ = this.store.pipe(select(
|
|
461
|
-
this.errors$ = this.store.pipe(select(
|
|
458
|
+
const { selectLoading, selectErrors, selectAuthLoggedIn, } = daffAuthSelectorFactory();
|
|
459
|
+
this.loading$ = this.store.pipe(select(selectLoading));
|
|
460
|
+
this.errors$ = this.store.pipe(select(selectErrors));
|
|
462
461
|
this.loggedIn$ = this.store.pipe(select(selectAuthLoggedIn));
|
|
463
462
|
}
|
|
464
463
|
dispatch(action) {
|
|
@@ -480,9 +479,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
480
479
|
class DaffAuthLoginFacade {
|
|
481
480
|
constructor(store) {
|
|
482
481
|
this.store = store;
|
|
483
|
-
const {
|
|
484
|
-
this.loading$ = this.store.pipe(select(
|
|
485
|
-
this.errors$ = this.store.pipe(select(
|
|
482
|
+
const { selectLoading, selectErrors, } = daffAuthLoginSelectorFactory();
|
|
483
|
+
this.loading$ = this.store.pipe(select(selectLoading));
|
|
484
|
+
this.errors$ = this.store.pipe(select(selectErrors));
|
|
486
485
|
}
|
|
487
486
|
dispatch(action) {
|
|
488
487
|
this.store.dispatch(action);
|
|
@@ -503,9 +502,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
503
502
|
class DaffAuthRegisterFacade {
|
|
504
503
|
constructor(store) {
|
|
505
504
|
this.store = store;
|
|
506
|
-
const {
|
|
507
|
-
this.loading$ = this.store.pipe(select(
|
|
508
|
-
this.errors$ = this.store.pipe(select(
|
|
505
|
+
const { selectLoading, selectErrors, } = daffAuthRegisterSelectorFactory();
|
|
506
|
+
this.loading$ = this.store.pipe(select(selectLoading));
|
|
507
|
+
this.errors$ = this.store.pipe(select(selectErrors));
|
|
509
508
|
}
|
|
510
509
|
dispatch(action) {
|
|
511
510
|
this.store.dispatch(action);
|
|
@@ -526,10 +525,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
526
525
|
class DaffAuthResetPasswordFacade {
|
|
527
526
|
constructor(store) {
|
|
528
527
|
this.store = store;
|
|
529
|
-
const {
|
|
528
|
+
const { selectLoading, selectErrors, selectAuthResetPasswordToken, } = daffAuthResetPasswordSelectorFactory();
|
|
530
529
|
this.token$ = this.store.pipe(select(selectAuthResetPasswordToken));
|
|
531
|
-
this.loading$ = this.store.pipe(select(
|
|
532
|
-
this.errors$ = this.store.pipe(select(
|
|
530
|
+
this.loading$ = this.store.pipe(select(selectLoading));
|
|
531
|
+
this.errors$ = this.store.pipe(select(selectErrors));
|
|
533
532
|
}
|
|
534
533
|
dispatch(action) {
|
|
535
534
|
this.store.dispatch(action);
|
|
@@ -555,14 +554,56 @@ const provideDaffAuthStateConfig = (config) => ({
|
|
|
555
554
|
useValue: config,
|
|
556
555
|
});
|
|
557
556
|
|
|
557
|
+
/**
|
|
558
|
+
* A token to hold the unauthenticated hooks.
|
|
559
|
+
* When a logged-in user is unauthenticated, various packages may perform cleanup tasks.
|
|
560
|
+
* These are guaranteed to run synchronously before the client driver state is fully reset.
|
|
561
|
+
*
|
|
562
|
+
* Prefer using {@link daffAuthProvideUnauthenticatedHooks}.
|
|
563
|
+
*/
|
|
564
|
+
const DAFF_AUTH_UNAUTHENTICATED_HOOKS = new InjectionToken('DAFF_AUTH_UNAUTHENTICATED_HOOKS', { factory: () => [] });
|
|
565
|
+
/**
|
|
566
|
+
* Provides {@link DAFF_AUTH_UNAUTHENTICATED_HOOKS}.
|
|
567
|
+
*
|
|
568
|
+
* ```ts
|
|
569
|
+
* providers: [
|
|
570
|
+
* ...daffAuthProvideUnauthenticatedHooks(
|
|
571
|
+
* myReducer1,
|
|
572
|
+
* myReducer2
|
|
573
|
+
* )
|
|
574
|
+
* ]
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
function daffAuthProvideUnauthenticatedHooks(...hooks) {
|
|
578
|
+
return hooks.map(hook => ({
|
|
579
|
+
provide: DAFF_AUTH_UNAUTHENTICATED_HOOKS,
|
|
580
|
+
useValue: hook,
|
|
581
|
+
multi: true,
|
|
582
|
+
}));
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* An internal token to hold the unauthenticated hook.
|
|
587
|
+
* Combines the multi provided hooks into a single function.
|
|
588
|
+
*
|
|
589
|
+
* @docs-private
|
|
590
|
+
*/
|
|
591
|
+
const DAFF_AUTH_UNAUTHENTICATED_HOOK = new InjectionToken('DAFF_AUTH_UNAUTHENTICATED_HOOK', {
|
|
592
|
+
factory: () => inject(DAFF_AUTH_UNAUTHENTICATED_HOOKS).reduce((acc, hook) => () => {
|
|
593
|
+
acc();
|
|
594
|
+
hook();
|
|
595
|
+
}, () => { }),
|
|
596
|
+
});
|
|
597
|
+
|
|
558
598
|
class DaffAuthEffects {
|
|
559
|
-
constructor(actions$, tokenCheck, errorMatcher, storage, config, clientCache) {
|
|
599
|
+
constructor(actions$, tokenCheck, errorMatcher, storage, config, clientCache, unauthenticatedHook) {
|
|
560
600
|
this.actions$ = actions$;
|
|
561
601
|
this.tokenCheck = tokenCheck;
|
|
562
602
|
this.errorMatcher = errorMatcher;
|
|
563
603
|
this.storage = storage;
|
|
564
604
|
this.config = config;
|
|
565
605
|
this.clientCache = clientCache;
|
|
606
|
+
this.unauthenticatedHook = unauthenticatedHook;
|
|
566
607
|
this.check$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthActionTypes.AuthCheckAction), switchMap((action) => this.tokenCheck.check().pipe(map(() => new DaffAuthCheckSuccess()), catchError((error) => of(new DaffAuthCheckFailure(this.errorMatcher(error))))))));
|
|
567
608
|
this.removeAuthToken$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthActionTypes.AuthCheckFailureAction), tap(() => {
|
|
568
609
|
this.storage.removeAuthToken();
|
|
@@ -586,12 +627,18 @@ class DaffAuthEffects {
|
|
|
586
627
|
return EMPTY;
|
|
587
628
|
}
|
|
588
629
|
})));
|
|
589
|
-
this.
|
|
630
|
+
this.resetToUnauthenticated$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthActionTypes.AuthCheckFailureAction, DaffAuthActionTypes.AuthGuardLogoutAction, DaffAuthLoginActionTypes.LogoutSuccessAction), map(() => new DaffAuthResetToUnauthenticated())));
|
|
631
|
+
this.clearClientCache$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthActionTypes.ResetToUnauthenticatedAction),
|
|
632
|
+
// map here to be sure that the stream waits for the hook to complete
|
|
633
|
+
// tap is for side effects and might use setTimeout
|
|
634
|
+
map(() => {
|
|
635
|
+
this.unauthenticatedHook();
|
|
636
|
+
}), tap(() => {
|
|
590
637
|
this.clientCache.reset();
|
|
591
638
|
}), switchMap(() => EMPTY)), { dispatch: false });
|
|
592
639
|
}
|
|
593
640
|
}
|
|
594
|
-
/** @nocollapse */ DaffAuthEffects.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthEffects, deps: [{ token: i1$1.Actions }, { token: i2.DaffAuthDriverTokenCheck }, { token: DAFF_AUTH_ERROR_MATCHER }, { token: i2$1.DaffAuthStorageService }, { token: DAFF_AUTH_STATE_CONFIG }, { token: DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
641
|
+
/** @nocollapse */ DaffAuthEffects.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthEffects, deps: [{ token: i1$1.Actions }, { token: i2.DaffAuthDriverTokenCheck }, { token: DAFF_AUTH_ERROR_MATCHER }, { token: i2$1.DaffAuthStorageService }, { token: DAFF_AUTH_STATE_CONFIG }, { token: DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE }, { token: DAFF_AUTH_UNAUTHENTICATED_HOOK }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
595
642
|
/** @nocollapse */ DaffAuthEffects.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthEffects });
|
|
596
643
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthEffects, decorators: [{
|
|
597
644
|
type: Injectable
|
|
@@ -605,6 +652,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
605
652
|
}] }, { type: undefined, decorators: [{
|
|
606
653
|
type: Inject,
|
|
607
654
|
args: [DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE]
|
|
655
|
+
}] }, { type: undefined, decorators: [{
|
|
656
|
+
type: Inject,
|
|
657
|
+
args: [DAFF_AUTH_UNAUTHENTICATED_HOOK]
|
|
608
658
|
}] }];
|
|
609
659
|
} });
|
|
610
660
|
|
|
@@ -614,30 +664,26 @@ class DaffAuthLoginEffects {
|
|
|
614
664
|
this.loginDriver = loginDriver;
|
|
615
665
|
this.errorMatcher = errorMatcher;
|
|
616
666
|
this.storage = storage;
|
|
617
|
-
this.login$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthLoginActionTypes.LoginAction), switchMap((action) => this.loginDriver.login(action.loginInfo)
|
|
618
|
-
|
|
619
|
-
this.removeAuthToken$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthLoginActionTypes.LogoutSuccessAction), tap(() => {
|
|
620
|
-
this.storage.removeAuthToken();
|
|
621
|
-
}), switchMap(() => EMPTY), catchError((error) => {
|
|
667
|
+
this.login$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthLoginActionTypes.LoginAction), switchMap((action) => this.loginDriver.login(action.loginInfo)
|
|
668
|
+
.pipe(map((resp) => new DaffAuthLoginSuccess(resp)), tap((success) => this.storage.setAuthToken(success.auth.token)), catchError((error) => {
|
|
622
669
|
switch (true) {
|
|
623
670
|
case error instanceof DaffServerSideStorageError:
|
|
624
671
|
return of(new DaffAuthServerSide(this.errorMatcher(error)));
|
|
625
672
|
case error instanceof DaffStorageServiceError:
|
|
626
673
|
default:
|
|
627
|
-
return of(new
|
|
674
|
+
return of(new DaffAuthLoginFailure(this.errorMatcher(error)));
|
|
628
675
|
}
|
|
629
|
-
}))
|
|
630
|
-
this.
|
|
631
|
-
this.storage.setAuthToken(action.auth.token);
|
|
632
|
-
}), switchMap(() => EMPTY), catchError((error) => {
|
|
676
|
+
})))));
|
|
677
|
+
this.logout$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthLoginActionTypes.LogoutAction), switchMap((action) => this.loginDriver.logout().pipe(map(() => new DaffAuthLogoutSuccess()), tap(() => this.storage.removeAuthToken()), catchError((error) => {
|
|
633
678
|
switch (true) {
|
|
634
679
|
case error instanceof DaffServerSideStorageError:
|
|
635
680
|
return of(new DaffAuthServerSide(this.errorMatcher(error)));
|
|
636
681
|
case error instanceof DaffStorageServiceError:
|
|
637
|
-
default:
|
|
638
682
|
return of(new DaffAuthStorageFailure(this.errorMatcher(error)));
|
|
683
|
+
default:
|
|
684
|
+
return of(new DaffAuthLogoutFailure(this.errorMatcher(error)));
|
|
639
685
|
}
|
|
640
|
-
}))
|
|
686
|
+
})))));
|
|
641
687
|
}
|
|
642
688
|
}
|
|
643
689
|
/** @nocollapse */ DaffAuthLoginEffects.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthLoginEffects, deps: [{ token: i1$1.Actions }, { token: DaffLoginDriver }, { token: DAFF_AUTH_ERROR_MATCHER }, { token: i2$1.DaffAuthStorageService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
@@ -719,6 +765,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
719
765
|
}] }, { type: i2$1.DaffAuthStorageService }];
|
|
720
766
|
} });
|
|
721
767
|
|
|
768
|
+
/**
|
|
769
|
+
* An internal token to hold the Daffodil auth reducers.
|
|
770
|
+
* Includes the extra and standard reducers.
|
|
771
|
+
*
|
|
772
|
+
* @docs-private
|
|
773
|
+
*/
|
|
774
|
+
const DAFF_AUTH_REDUCERS = new InjectionToken('DAFF_AUTH_REDUCERS', {
|
|
775
|
+
factory: () => daffComposeReducers([
|
|
776
|
+
combineReducers(daffAuthReducers),
|
|
777
|
+
...inject(DAFF_AUTH_EXTRA_REDUCERS),
|
|
778
|
+
]),
|
|
779
|
+
});
|
|
780
|
+
|
|
722
781
|
class DaffAuthStateModule {
|
|
723
782
|
static withConfig(config = {}) {
|
|
724
783
|
return {
|
|
@@ -732,7 +791,7 @@ class DaffAuthStateModule {
|
|
|
732
791
|
/** @nocollapse */ DaffAuthStateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthStateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
733
792
|
/** @nocollapse */ DaffAuthStateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthStateModule, imports: [i1.StoreFeatureModule, i1$1.EffectsFeatureModule] });
|
|
734
793
|
/** @nocollapse */ DaffAuthStateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthStateModule, imports: [[
|
|
735
|
-
StoreModule.forFeature(DAFF_AUTH_STORE_FEATURE_KEY,
|
|
794
|
+
StoreModule.forFeature(DAFF_AUTH_STORE_FEATURE_KEY, DAFF_AUTH_REDUCERS),
|
|
736
795
|
EffectsModule.forFeature([
|
|
737
796
|
DaffAuthEffects,
|
|
738
797
|
DaffAuthLoginEffects,
|
|
@@ -744,7 +803,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
744
803
|
type: NgModule,
|
|
745
804
|
args: [{
|
|
746
805
|
imports: [
|
|
747
|
-
StoreModule.forFeature(DAFF_AUTH_STORE_FEATURE_KEY,
|
|
806
|
+
StoreModule.forFeature(DAFF_AUTH_STORE_FEATURE_KEY, DAFF_AUTH_REDUCERS),
|
|
748
807
|
EffectsModule.forFeature([
|
|
749
808
|
DaffAuthEffects,
|
|
750
809
|
DaffAuthLoginEffects,
|
|
@@ -759,5 +818,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
759
818
|
* Generated bundle index. Do not edit.
|
|
760
819
|
*/
|
|
761
820
|
|
|
762
|
-
export { DAFF_AUTH_STATE_CONFIG, DAFF_AUTH_STORE_FEATURE_KEY, DaffAuthActionTypes, DaffAuthCheck, DaffAuthCheckFailure, DaffAuthCheckSuccess, DaffAuthFacade, DaffAuthGuardLogout, DaffAuthLogin, DaffAuthLoginActionTypes, DaffAuthLoginFacade, DaffAuthLoginFailure, DaffAuthLoginSuccess, DaffAuthLogout, DaffAuthLogoutFailure, DaffAuthLogoutSuccess, DaffAuthRegister, DaffAuthRegisterActionTypes, DaffAuthRegisterFacade, DaffAuthRegisterFailure, DaffAuthRegisterSuccess, DaffAuthResetPasswordActionTypes, DaffAuthResetPasswordFacade, DaffAuthServerSide, DaffAuthStateModule, DaffAuthStorageFailure, DaffResetPassword, DaffResetPasswordFailure, DaffResetPasswordLanding, DaffResetPasswordSuccess, DaffSendResetEmail, DaffSendResetEmailFailure, DaffSendResetEmailSuccess, daffAuthInitialState, daffAuthLoginInitialState, daffAuthLoginReducer, daffAuthReducer, daffAuthReducers, daffAuthRegisterInitialState, daffAuthRegisterReducer, daffAuthResetPasswordInitialState, daffAuthResetPasswordReducer, daffAuthStateDefaultConfig, getDaffAuthSelectors, provideDaffAuthStateConfig };
|
|
821
|
+
export { DAFF_AUTH_EXTRA_REDUCERS, DAFF_AUTH_STATE_CONFIG, DAFF_AUTH_STORE_FEATURE_KEY, DAFF_AUTH_UNAUTHENTICATED_HOOKS, DaffAuthActionTypes, DaffAuthCheck, DaffAuthCheckFailure, DaffAuthCheckSuccess, DaffAuthFacade, DaffAuthGuardLogout, DaffAuthLogin, DaffAuthLoginActionTypes, DaffAuthLoginFacade, DaffAuthLoginFailure, DaffAuthLoginSuccess, DaffAuthLogout, DaffAuthLogoutFailure, DaffAuthLogoutSuccess, DaffAuthRegister, DaffAuthRegisterActionTypes, DaffAuthRegisterFacade, DaffAuthRegisterFailure, DaffAuthRegisterSuccess, DaffAuthResetPasswordActionTypes, DaffAuthResetPasswordFacade, DaffAuthResetToUnauthenticated, DaffAuthServerSide, DaffAuthStateModule, DaffAuthStorageFailure, DaffResetPassword, DaffResetPasswordFailure, DaffResetPasswordLanding, DaffResetPasswordSuccess, DaffSendResetEmail, DaffSendResetEmailFailure, DaffSendResetEmailSuccess, daffAuthInitialState, daffAuthLoginInitialState, daffAuthLoginReducer, daffAuthLoginSelectorFactory, daffAuthProvideExtraReducers, daffAuthProvideUnauthenticatedHooks, daffAuthReducer, daffAuthReducers, daffAuthRegisterInitialState, daffAuthRegisterReducer, daffAuthRegisterSelectorFactory, daffAuthResetPasswordInitialState, daffAuthResetPasswordReducer, daffAuthResetPasswordSelectorFactory, daffAuthSelectorFactory, daffAuthStateDefaultConfig, getDaffAuthSelectors, provideDaffAuthStateConfig };
|
|
763
822
|
//# sourceMappingURL=daffodil-auth-state.mjs.map
|