@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 { DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE } from '@daffodil/driver';
|
|
|
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
|
*/
|
|
@@ -272,40 +283,28 @@ class DaffResetPasswordLanding {
|
|
|
272
283
|
}
|
|
273
284
|
|
|
274
285
|
const daffAuthInitialState = {
|
|
275
|
-
|
|
276
|
-
errors: [],
|
|
286
|
+
...daffOperationInitialState,
|
|
277
287
|
loggedIn: false,
|
|
278
288
|
};
|
|
279
289
|
|
|
280
290
|
function daffAuthReducer(state = daffAuthInitialState, action) {
|
|
281
291
|
switch (action.type) {
|
|
282
292
|
case DaffAuthActionTypes.AuthCheckAction:
|
|
283
|
-
return
|
|
284
|
-
...state,
|
|
285
|
-
loading: true,
|
|
286
|
-
};
|
|
293
|
+
return daffStartResolution(state);
|
|
287
294
|
case DaffAuthActionTypes.AuthCheckSuccessAction:
|
|
288
295
|
return {
|
|
289
|
-
...state,
|
|
296
|
+
...daffCompleteOperation(state),
|
|
290
297
|
loggedIn: true,
|
|
291
|
-
loading: false,
|
|
292
|
-
errors: [],
|
|
293
298
|
};
|
|
294
299
|
case DaffAuthActionTypes.AuthCheckFailureAction:
|
|
295
300
|
case DaffAuthActionTypes.AuthGuardLogoutAction:
|
|
296
301
|
return {
|
|
297
|
-
...state,
|
|
302
|
+
...daffOperationFailed([action.errorMessage], state),
|
|
298
303
|
loggedIn: false,
|
|
299
|
-
loading: false,
|
|
300
|
-
errors: [action.errorMessage],
|
|
301
304
|
};
|
|
302
305
|
case DaffAuthActionTypes.AuthServerSideAction:
|
|
303
306
|
case DaffAuthActionTypes.AuthStorageFailureAction:
|
|
304
|
-
return
|
|
305
|
-
...state,
|
|
306
|
-
loading: false,
|
|
307
|
-
errors: [action.errorMessage],
|
|
308
|
-
};
|
|
307
|
+
return daffOperationFailed([action.errorMessage], state);
|
|
309
308
|
case DaffAuthLoginActionTypes.LoginSuccessAction:
|
|
310
309
|
return {
|
|
311
310
|
...state,
|
|
@@ -327,70 +326,41 @@ function daffAuthReducer(state = daffAuthInitialState, action) {
|
|
|
327
326
|
}
|
|
328
327
|
}
|
|
329
328
|
|
|
330
|
-
const daffAuthLoginInitialState =
|
|
331
|
-
loading: false,
|
|
332
|
-
errors: [],
|
|
333
|
-
};
|
|
329
|
+
const daffAuthLoginInitialState = daffOperationInitialState;
|
|
334
330
|
|
|
335
331
|
function daffAuthLoginReducer(state = daffAuthLoginInitialState, action) {
|
|
336
332
|
switch (action.type) {
|
|
337
333
|
case DaffAuthLoginActionTypes.LoginAction:
|
|
338
334
|
case DaffAuthLoginActionTypes.LogoutAction:
|
|
339
|
-
return
|
|
340
|
-
...state,
|
|
341
|
-
loading: true,
|
|
342
|
-
};
|
|
335
|
+
return daffStartMutation(state);
|
|
343
336
|
case DaffAuthLoginActionTypes.LoginSuccessAction:
|
|
344
337
|
case DaffAuthLoginActionTypes.LogoutSuccessAction:
|
|
345
|
-
return
|
|
346
|
-
...state,
|
|
347
|
-
loading: false,
|
|
348
|
-
errors: [],
|
|
349
|
-
};
|
|
338
|
+
return daffCompleteOperation(state);
|
|
350
339
|
case DaffAuthLoginActionTypes.LoginFailureAction:
|
|
351
340
|
case DaffAuthLoginActionTypes.LogoutFailureAction:
|
|
352
|
-
return
|
|
353
|
-
...state,
|
|
354
|
-
loading: false,
|
|
355
|
-
errors: [action.errorMessage],
|
|
356
|
-
};
|
|
341
|
+
return daffOperationFailed([action.errorMessage], state);
|
|
357
342
|
default:
|
|
358
343
|
return state;
|
|
359
344
|
}
|
|
360
345
|
}
|
|
361
346
|
|
|
362
|
-
const daffAuthRegisterInitialState =
|
|
363
|
-
loading: false,
|
|
364
|
-
errors: [],
|
|
365
|
-
};
|
|
347
|
+
const daffAuthRegisterInitialState = daffOperationInitialState;
|
|
366
348
|
|
|
367
349
|
function daffAuthRegisterReducer(state = daffAuthRegisterInitialState, action) {
|
|
368
350
|
switch (action.type) {
|
|
369
351
|
case DaffAuthRegisterActionTypes.RegisterAction:
|
|
370
|
-
return
|
|
371
|
-
...state,
|
|
372
|
-
loading: true,
|
|
373
|
-
};
|
|
352
|
+
return daffStartMutation(state);
|
|
374
353
|
case DaffAuthRegisterActionTypes.RegisterSuccessAction:
|
|
375
|
-
return
|
|
376
|
-
...state,
|
|
377
|
-
loading: false,
|
|
378
|
-
errors: [],
|
|
379
|
-
};
|
|
354
|
+
return daffCompleteOperation(state);
|
|
380
355
|
case DaffAuthRegisterActionTypes.RegisterFailureAction:
|
|
381
|
-
return
|
|
382
|
-
...state,
|
|
383
|
-
loading: false,
|
|
384
|
-
errors: [action.errorMessage],
|
|
385
|
-
};
|
|
356
|
+
return daffOperationFailed([action.errorMessage], state);
|
|
386
357
|
default:
|
|
387
358
|
return state;
|
|
388
359
|
}
|
|
389
360
|
}
|
|
390
361
|
|
|
391
362
|
const daffAuthResetPasswordInitialState = {
|
|
392
|
-
|
|
393
|
-
errors: [],
|
|
363
|
+
...daffOperationInitialState,
|
|
394
364
|
token: null,
|
|
395
365
|
};
|
|
396
366
|
|
|
@@ -398,24 +368,13 @@ function daffAuthResetPasswordReducer(state = daffAuthResetPasswordInitialState,
|
|
|
398
368
|
switch (action.type) {
|
|
399
369
|
case DaffAuthResetPasswordActionTypes.ResetPasswordAction:
|
|
400
370
|
case DaffAuthResetPasswordActionTypes.SendResetEmailAction:
|
|
401
|
-
return
|
|
402
|
-
...state,
|
|
403
|
-
loading: true,
|
|
404
|
-
};
|
|
371
|
+
return daffStartMutation(state);
|
|
405
372
|
case DaffAuthResetPasswordActionTypes.ResetPasswordSuccessAction:
|
|
406
373
|
case DaffAuthResetPasswordActionTypes.SendResetEmailSuccessAction:
|
|
407
|
-
return
|
|
408
|
-
...state,
|
|
409
|
-
loading: false,
|
|
410
|
-
errors: [],
|
|
411
|
-
};
|
|
374
|
+
return daffCompleteOperation(state);
|
|
412
375
|
case DaffAuthResetPasswordActionTypes.ResetPasswordFailureAction:
|
|
413
376
|
case DaffAuthResetPasswordActionTypes.SendResetEmailFailureAction:
|
|
414
|
-
return
|
|
415
|
-
...state,
|
|
416
|
-
loading: false,
|
|
417
|
-
errors: [action.errorMessage],
|
|
418
|
-
};
|
|
377
|
+
return daffOperationFailed([action.errorMessage], state);
|
|
419
378
|
case DaffAuthResetPasswordActionTypes.ResetPasswordLandingAction:
|
|
420
379
|
return {
|
|
421
380
|
...state,
|
|
@@ -426,6 +385,32 @@ function daffAuthResetPasswordReducer(state = daffAuthResetPasswordInitialState,
|
|
|
426
385
|
}
|
|
427
386
|
}
|
|
428
387
|
|
|
388
|
+
/**
|
|
389
|
+
* A token to hold the injectable extra reducers.
|
|
390
|
+
*
|
|
391
|
+
* Prefer using {@link daffAuthProvideExtraReducers}.
|
|
392
|
+
*/
|
|
393
|
+
const DAFF_AUTH_EXTRA_REDUCERS = new InjectionToken('DAFF_AUTH_EXTRA_REDUCERS', { factory: () => [] });
|
|
394
|
+
/**
|
|
395
|
+
* Provides additional reducers that run after the standard Daffodil auth reducers.
|
|
396
|
+
*
|
|
397
|
+
* ```ts
|
|
398
|
+
* providers: [
|
|
399
|
+
* ...daffAuthProvideExtraReducers(
|
|
400
|
+
* myReducer1,
|
|
401
|
+
* myReducer2
|
|
402
|
+
* )
|
|
403
|
+
* ]
|
|
404
|
+
* ```
|
|
405
|
+
*/
|
|
406
|
+
function daffAuthProvideExtraReducers(...reducers) {
|
|
407
|
+
return reducers.map(reducer => ({
|
|
408
|
+
provide: DAFF_AUTH_EXTRA_REDUCERS,
|
|
409
|
+
useValue: reducer,
|
|
410
|
+
multi: true,
|
|
411
|
+
}));
|
|
412
|
+
}
|
|
413
|
+
|
|
429
414
|
const DAFF_AUTH_STORE_FEATURE_KEY = 'daffAuth';
|
|
430
415
|
|
|
431
416
|
const daffAuthReducers = {
|
|
@@ -445,64 +430,52 @@ const getDaffAuthFeatureStateSelector = (() => {
|
|
|
445
430
|
|
|
446
431
|
const createAuthSelectors = () => {
|
|
447
432
|
const selectAuthState = createSelector(getDaffAuthFeatureStateSelector(), state => state.auth);
|
|
448
|
-
const selectAuthLoading = createSelector(selectAuthState, state => state.loading);
|
|
449
|
-
const selectAuthErrors = createSelector(selectAuthState, state => state.errors);
|
|
450
433
|
const selectAuthLoggedIn = createSelector(selectAuthState, state => state.loggedIn);
|
|
451
434
|
return {
|
|
435
|
+
...daffOperationStateSelectorFactory(selectAuthState),
|
|
452
436
|
selectAuthState,
|
|
453
|
-
selectAuthLoading,
|
|
454
|
-
selectAuthErrors,
|
|
455
437
|
selectAuthLoggedIn,
|
|
456
438
|
};
|
|
457
439
|
};
|
|
458
|
-
const
|
|
440
|
+
const daffAuthSelectorFactory = (() => {
|
|
459
441
|
let cache;
|
|
460
442
|
return () => cache = cache || createAuthSelectors();
|
|
461
443
|
})();
|
|
462
444
|
|
|
463
445
|
const createLoginSelectors = () => {
|
|
464
446
|
const selectAuthLoginState = createSelector(getDaffAuthFeatureStateSelector(), state => state.login);
|
|
465
|
-
const selectAuthLoginLoading = createSelector(selectAuthLoginState, state => state.loading);
|
|
466
|
-
const selectAuthLoginErrors = createSelector(selectAuthLoginState, state => state.errors);
|
|
467
447
|
return {
|
|
448
|
+
...daffOperationStateSelectorFactory(selectAuthLoginState),
|
|
468
449
|
selectAuthLoginState,
|
|
469
|
-
selectAuthLoginLoading,
|
|
470
|
-
selectAuthLoginErrors,
|
|
471
450
|
};
|
|
472
451
|
};
|
|
473
|
-
const
|
|
452
|
+
const daffAuthLoginSelectorFactory = (() => {
|
|
474
453
|
let cache;
|
|
475
454
|
return () => cache = cache || createLoginSelectors();
|
|
476
455
|
})();
|
|
477
456
|
|
|
478
457
|
const createRegisterSelectors = () => {
|
|
479
458
|
const selectAuthRegisterState = createSelector(getDaffAuthFeatureStateSelector(), state => state.register);
|
|
480
|
-
const selectAuthRegisterLoading = createSelector(selectAuthRegisterState, state => state.loading);
|
|
481
|
-
const selectAuthRegisterErrors = createSelector(selectAuthRegisterState, state => state.errors);
|
|
482
459
|
return {
|
|
460
|
+
...daffOperationStateSelectorFactory(selectAuthRegisterState),
|
|
483
461
|
selectAuthRegisterState,
|
|
484
|
-
selectAuthRegisterLoading,
|
|
485
|
-
selectAuthRegisterErrors,
|
|
486
462
|
};
|
|
487
463
|
};
|
|
488
|
-
const
|
|
464
|
+
const daffAuthRegisterSelectorFactory = (() => {
|
|
489
465
|
let cache;
|
|
490
466
|
return () => cache = cache || createRegisterSelectors();
|
|
491
467
|
})();
|
|
492
468
|
|
|
493
469
|
const createResetPasswordSelectors = () => {
|
|
494
470
|
const selectAuthResetPasswordState = createSelector(getDaffAuthFeatureStateSelector(), state => state.resetPassword);
|
|
495
|
-
const selectAuthResetPasswordLoading = createSelector(selectAuthResetPasswordState, state => state.loading);
|
|
496
|
-
const selectAuthResetPasswordErrors = createSelector(selectAuthResetPasswordState, state => state.errors);
|
|
497
471
|
const selectAuthResetPasswordToken = createSelector(selectAuthResetPasswordState, state => state.token);
|
|
498
472
|
return {
|
|
473
|
+
...daffOperationStateSelectorFactory(selectAuthResetPasswordState),
|
|
499
474
|
selectAuthResetPasswordState,
|
|
500
|
-
selectAuthResetPasswordLoading,
|
|
501
|
-
selectAuthResetPasswordErrors,
|
|
502
475
|
selectAuthResetPasswordToken,
|
|
503
476
|
};
|
|
504
477
|
};
|
|
505
|
-
const
|
|
478
|
+
const daffAuthResetPasswordSelectorFactory = (() => {
|
|
506
479
|
let cache;
|
|
507
480
|
return () => cache = cache || createResetPasswordSelectors();
|
|
508
481
|
})();
|
|
@@ -510,10 +483,10 @@ const getDaffAuthResetPasswordSelectors = (() => {
|
|
|
510
483
|
const getDaffAuthSelectors = (() => {
|
|
511
484
|
let cache;
|
|
512
485
|
return () => cache = cache || {
|
|
513
|
-
...
|
|
514
|
-
...
|
|
515
|
-
...
|
|
516
|
-
...
|
|
486
|
+
...daffAuthSelectorFactory(),
|
|
487
|
+
...daffAuthLoginSelectorFactory(),
|
|
488
|
+
...daffAuthRegisterSelectorFactory(),
|
|
489
|
+
...daffAuthResetPasswordSelectorFactory(),
|
|
517
490
|
selectAuthFeatureState: getDaffAuthFeatureStateSelector(),
|
|
518
491
|
};
|
|
519
492
|
})();
|
|
@@ -524,9 +497,9 @@ const getDaffAuthSelectors = (() => {
|
|
|
524
497
|
class DaffAuthFacade {
|
|
525
498
|
constructor(store) {
|
|
526
499
|
this.store = store;
|
|
527
|
-
const {
|
|
528
|
-
this.loading$ = this.store.pipe(select(
|
|
529
|
-
this.errors$ = this.store.pipe(select(
|
|
500
|
+
const { selectLoading, selectErrors, selectAuthLoggedIn, } = daffAuthSelectorFactory();
|
|
501
|
+
this.loading$ = this.store.pipe(select(selectLoading));
|
|
502
|
+
this.errors$ = this.store.pipe(select(selectErrors));
|
|
530
503
|
this.loggedIn$ = this.store.pipe(select(selectAuthLoggedIn));
|
|
531
504
|
}
|
|
532
505
|
dispatch(action) {
|
|
@@ -548,9 +521,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
548
521
|
class DaffAuthLoginFacade {
|
|
549
522
|
constructor(store) {
|
|
550
523
|
this.store = store;
|
|
551
|
-
const {
|
|
552
|
-
this.loading$ = this.store.pipe(select(
|
|
553
|
-
this.errors$ = this.store.pipe(select(
|
|
524
|
+
const { selectLoading, selectErrors, } = daffAuthLoginSelectorFactory();
|
|
525
|
+
this.loading$ = this.store.pipe(select(selectLoading));
|
|
526
|
+
this.errors$ = this.store.pipe(select(selectErrors));
|
|
554
527
|
}
|
|
555
528
|
dispatch(action) {
|
|
556
529
|
this.store.dispatch(action);
|
|
@@ -571,9 +544,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
571
544
|
class DaffAuthRegisterFacade {
|
|
572
545
|
constructor(store) {
|
|
573
546
|
this.store = store;
|
|
574
|
-
const {
|
|
575
|
-
this.loading$ = this.store.pipe(select(
|
|
576
|
-
this.errors$ = this.store.pipe(select(
|
|
547
|
+
const { selectLoading, selectErrors, } = daffAuthRegisterSelectorFactory();
|
|
548
|
+
this.loading$ = this.store.pipe(select(selectLoading));
|
|
549
|
+
this.errors$ = this.store.pipe(select(selectErrors));
|
|
577
550
|
}
|
|
578
551
|
dispatch(action) {
|
|
579
552
|
this.store.dispatch(action);
|
|
@@ -594,10 +567,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
594
567
|
class DaffAuthResetPasswordFacade {
|
|
595
568
|
constructor(store) {
|
|
596
569
|
this.store = store;
|
|
597
|
-
const {
|
|
570
|
+
const { selectLoading, selectErrors, selectAuthResetPasswordToken, } = daffAuthResetPasswordSelectorFactory();
|
|
598
571
|
this.token$ = this.store.pipe(select(selectAuthResetPasswordToken));
|
|
599
|
-
this.loading$ = this.store.pipe(select(
|
|
600
|
-
this.errors$ = this.store.pipe(select(
|
|
572
|
+
this.loading$ = this.store.pipe(select(selectLoading));
|
|
573
|
+
this.errors$ = this.store.pipe(select(selectErrors));
|
|
601
574
|
}
|
|
602
575
|
dispatch(action) {
|
|
603
576
|
this.store.dispatch(action);
|
|
@@ -623,14 +596,56 @@ const provideDaffAuthStateConfig = (config) => ({
|
|
|
623
596
|
useValue: config,
|
|
624
597
|
});
|
|
625
598
|
|
|
599
|
+
/**
|
|
600
|
+
* A token to hold the unauthenticated hooks.
|
|
601
|
+
* When a logged-in user is unauthenticated, various packages may perform cleanup tasks.
|
|
602
|
+
* These are guaranteed to run synchronously before the client driver state is fully reset.
|
|
603
|
+
*
|
|
604
|
+
* Prefer using {@link daffAuthProvideUnauthenticatedHooks}.
|
|
605
|
+
*/
|
|
606
|
+
const DAFF_AUTH_UNAUTHENTICATED_HOOKS = new InjectionToken('DAFF_AUTH_UNAUTHENTICATED_HOOKS', { factory: () => [] });
|
|
607
|
+
/**
|
|
608
|
+
* Provides {@link DAFF_AUTH_UNAUTHENTICATED_HOOKS}.
|
|
609
|
+
*
|
|
610
|
+
* ```ts
|
|
611
|
+
* providers: [
|
|
612
|
+
* ...daffAuthProvideUnauthenticatedHooks(
|
|
613
|
+
* myReducer1,
|
|
614
|
+
* myReducer2
|
|
615
|
+
* )
|
|
616
|
+
* ]
|
|
617
|
+
* ```
|
|
618
|
+
*/
|
|
619
|
+
function daffAuthProvideUnauthenticatedHooks(...hooks) {
|
|
620
|
+
return hooks.map(hook => ({
|
|
621
|
+
provide: DAFF_AUTH_UNAUTHENTICATED_HOOKS,
|
|
622
|
+
useValue: hook,
|
|
623
|
+
multi: true,
|
|
624
|
+
}));
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* An internal token to hold the unauthenticated hook.
|
|
629
|
+
* Combines the multi provided hooks into a single function.
|
|
630
|
+
*
|
|
631
|
+
* @docs-private
|
|
632
|
+
*/
|
|
633
|
+
const DAFF_AUTH_UNAUTHENTICATED_HOOK = new InjectionToken('DAFF_AUTH_UNAUTHENTICATED_HOOK', {
|
|
634
|
+
factory: () => inject(DAFF_AUTH_UNAUTHENTICATED_HOOKS).reduce((acc, hook) => () => {
|
|
635
|
+
acc();
|
|
636
|
+
hook();
|
|
637
|
+
}, () => { }),
|
|
638
|
+
});
|
|
639
|
+
|
|
626
640
|
class DaffAuthEffects {
|
|
627
|
-
constructor(actions$, tokenCheck, errorMatcher, storage, config, clientCache) {
|
|
641
|
+
constructor(actions$, tokenCheck, errorMatcher, storage, config, clientCache, unauthenticatedHook) {
|
|
628
642
|
this.actions$ = actions$;
|
|
629
643
|
this.tokenCheck = tokenCheck;
|
|
630
644
|
this.errorMatcher = errorMatcher;
|
|
631
645
|
this.storage = storage;
|
|
632
646
|
this.config = config;
|
|
633
647
|
this.clientCache = clientCache;
|
|
648
|
+
this.unauthenticatedHook = unauthenticatedHook;
|
|
634
649
|
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))))))));
|
|
635
650
|
this.removeAuthToken$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthActionTypes.AuthCheckFailureAction), tap(() => {
|
|
636
651
|
this.storage.removeAuthToken();
|
|
@@ -654,12 +669,18 @@ class DaffAuthEffects {
|
|
|
654
669
|
return EMPTY;
|
|
655
670
|
}
|
|
656
671
|
})));
|
|
657
|
-
this.
|
|
672
|
+
this.resetToUnauthenticated$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthActionTypes.AuthCheckFailureAction, DaffAuthActionTypes.AuthGuardLogoutAction, DaffAuthLoginActionTypes.LogoutSuccessAction), map(() => new DaffAuthResetToUnauthenticated())));
|
|
673
|
+
this.clearClientCache$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthActionTypes.ResetToUnauthenticatedAction),
|
|
674
|
+
// map here to be sure that the stream waits for the hook to complete
|
|
675
|
+
// tap is for side effects and might use setTimeout
|
|
676
|
+
map(() => {
|
|
677
|
+
this.unauthenticatedHook();
|
|
678
|
+
}), tap(() => {
|
|
658
679
|
this.clientCache.reset();
|
|
659
680
|
}), switchMap(() => EMPTY)), { dispatch: false });
|
|
660
681
|
}
|
|
661
682
|
}
|
|
662
|
-
/** @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 });
|
|
683
|
+
/** @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 });
|
|
663
684
|
/** @nocollapse */ DaffAuthEffects.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthEffects });
|
|
664
685
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthEffects, decorators: [{
|
|
665
686
|
type: Injectable
|
|
@@ -672,6 +693,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
672
693
|
}] }, { type: undefined, decorators: [{
|
|
673
694
|
type: Inject,
|
|
674
695
|
args: [DAFF_DRIVER_HTTP_CLIENT_CACHE_SERVICE]
|
|
696
|
+
}] }, { type: undefined, decorators: [{
|
|
697
|
+
type: Inject,
|
|
698
|
+
args: [DAFF_AUTH_UNAUTHENTICATED_HOOK]
|
|
675
699
|
}] }]; } });
|
|
676
700
|
|
|
677
701
|
class DaffAuthLoginEffects {
|
|
@@ -680,30 +704,26 @@ class DaffAuthLoginEffects {
|
|
|
680
704
|
this.loginDriver = loginDriver;
|
|
681
705
|
this.errorMatcher = errorMatcher;
|
|
682
706
|
this.storage = storage;
|
|
683
|
-
this.login$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthLoginActionTypes.LoginAction), switchMap((action) => this.loginDriver.login(action.loginInfo)
|
|
684
|
-
|
|
685
|
-
this.removeAuthToken$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthLoginActionTypes.LogoutSuccessAction), tap(() => {
|
|
686
|
-
this.storage.removeAuthToken();
|
|
687
|
-
}), switchMap(() => EMPTY), catchError((error) => {
|
|
707
|
+
this.login$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthLoginActionTypes.LoginAction), switchMap((action) => this.loginDriver.login(action.loginInfo)
|
|
708
|
+
.pipe(map((resp) => new DaffAuthLoginSuccess(resp)), tap((success) => this.storage.setAuthToken(success.auth.token)), catchError((error) => {
|
|
688
709
|
switch (true) {
|
|
689
710
|
case error instanceof DaffServerSideStorageError:
|
|
690
711
|
return of(new DaffAuthServerSide(this.errorMatcher(error)));
|
|
691
712
|
case error instanceof DaffStorageServiceError:
|
|
692
713
|
default:
|
|
693
|
-
return of(new
|
|
714
|
+
return of(new DaffAuthLoginFailure(this.errorMatcher(error)));
|
|
694
715
|
}
|
|
695
|
-
}))
|
|
696
|
-
this.
|
|
697
|
-
this.storage.setAuthToken(action.auth.token);
|
|
698
|
-
}), switchMap(() => EMPTY), catchError((error) => {
|
|
716
|
+
})))));
|
|
717
|
+
this.logout$ = createEffect(() => this.actions$.pipe(ofType(DaffAuthLoginActionTypes.LogoutAction), switchMap((action) => this.loginDriver.logout().pipe(map(() => new DaffAuthLogoutSuccess()), tap(() => this.storage.removeAuthToken()), catchError((error) => {
|
|
699
718
|
switch (true) {
|
|
700
719
|
case error instanceof DaffServerSideStorageError:
|
|
701
720
|
return of(new DaffAuthServerSide(this.errorMatcher(error)));
|
|
702
721
|
case error instanceof DaffStorageServiceError:
|
|
703
|
-
default:
|
|
704
722
|
return of(new DaffAuthStorageFailure(this.errorMatcher(error)));
|
|
723
|
+
default:
|
|
724
|
+
return of(new DaffAuthLogoutFailure(this.errorMatcher(error)));
|
|
705
725
|
}
|
|
706
|
-
}))
|
|
726
|
+
})))));
|
|
707
727
|
}
|
|
708
728
|
}
|
|
709
729
|
/** @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 });
|
|
@@ -779,6 +799,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
779
799
|
args: [DAFF_AUTH_ERROR_MATCHER]
|
|
780
800
|
}] }, { type: i2$1.DaffAuthStorageService }]; } });
|
|
781
801
|
|
|
802
|
+
/**
|
|
803
|
+
* An internal token to hold the Daffodil auth reducers.
|
|
804
|
+
* Includes the extra and standard reducers.
|
|
805
|
+
*
|
|
806
|
+
* @docs-private
|
|
807
|
+
*/
|
|
808
|
+
const DAFF_AUTH_REDUCERS = new InjectionToken('DAFF_AUTH_REDUCERS', {
|
|
809
|
+
factory: () => daffComposeReducers([
|
|
810
|
+
combineReducers(daffAuthReducers),
|
|
811
|
+
...inject(DAFF_AUTH_EXTRA_REDUCERS),
|
|
812
|
+
]),
|
|
813
|
+
});
|
|
814
|
+
|
|
782
815
|
class DaffAuthStateModule {
|
|
783
816
|
static withConfig(config = {}) {
|
|
784
817
|
return {
|
|
@@ -795,7 +828,7 @@ class DaffAuthStateModule {
|
|
|
795
828
|
/** @nocollapse */ DaffAuthStateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthStateModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
796
829
|
/** @nocollapse */ DaffAuthStateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthStateModule, imports: [i1.StoreFeatureModule, i1$1.EffectsFeatureModule] });
|
|
797
830
|
/** @nocollapse */ DaffAuthStateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.0", ngImport: i0, type: DaffAuthStateModule, imports: [[
|
|
798
|
-
StoreModule.forFeature(DAFF_AUTH_STORE_FEATURE_KEY,
|
|
831
|
+
StoreModule.forFeature(DAFF_AUTH_STORE_FEATURE_KEY, DAFF_AUTH_REDUCERS),
|
|
799
832
|
EffectsModule.forFeature([
|
|
800
833
|
DaffAuthEffects,
|
|
801
834
|
DaffAuthLoginEffects,
|
|
@@ -807,7 +840,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
807
840
|
type: NgModule,
|
|
808
841
|
args: [{
|
|
809
842
|
imports: [
|
|
810
|
-
StoreModule.forFeature(DAFF_AUTH_STORE_FEATURE_KEY,
|
|
843
|
+
StoreModule.forFeature(DAFF_AUTH_STORE_FEATURE_KEY, DAFF_AUTH_REDUCERS),
|
|
811
844
|
EffectsModule.forFeature([
|
|
812
845
|
DaffAuthEffects,
|
|
813
846
|
DaffAuthLoginEffects,
|
|
@@ -822,5 +855,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.0", ngImpor
|
|
|
822
855
|
* Generated bundle index. Do not edit.
|
|
823
856
|
*/
|
|
824
857
|
|
|
825
|
-
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 };
|
|
858
|
+
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 };
|
|
826
859
|
//# sourceMappingURL=daffodil-auth-state.mjs.map
|