@dsivd/prestations-ng 15.2.3-beta4 → 15.2.3-beta7

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.
@@ -31,32 +31,46 @@ import weekOfYear from 'dayjs/plugin/weekOfYear';
31
31
 
32
32
  /* eslint-disable @typescript-eslint/no-explicit-any */
33
33
  const IAM_SESSION_EXPIRED_HEADER = 'iam-session-expired';
34
- const LOGIN_PATH = '/100018/login';
34
+ const CYBER_LOGIN_PATH = '/100018/login';
35
+ const ACV_LOGIN_PATH = '/iamlogin';
36
+ const isIamExpiredHeader = (event) => !!event.headers.get(IAM_SESSION_EXPIRED_HEADER);
37
+ const isRedirectionToIamACV = (event) => {
38
+ const isRedirection = event.status === 302 /* Found */;
39
+ const location = event.headers.get('Location');
40
+ return isRedirection && location?.includes(ACV_LOGIN_PATH);
41
+ };
42
+ const isRedirectionToCyberLogin = (event) => {
43
+ const isRedirection = event.status === 302 /* Found */;
44
+ const location = event.headers.get('Location');
45
+ return isRedirection && location?.includes(CYBER_LOGIN_PATH);
46
+ };
35
47
  class IamExpiredInterceptorService {
36
48
  constructor() {
37
- this._iamExpirationHeaderPresence = new Subject();
49
+ this._isIamSessionExpired = new Subject();
38
50
  }
39
- get iamExpirationHeaderPresence() {
40
- return this._iamExpirationHeaderPresence.asObservable();
51
+ get isIamSessionExpired() {
52
+ return this._isIamSessionExpired.asObservable();
41
53
  }
42
54
  intercept(req, next) {
43
55
  return next.handle(req).pipe(map(event => {
56
+ console.log('event', typeof event, event);
44
57
  if (event instanceof HttpResponse) {
45
- // either we have the header 'iam-session-expired'
46
- const iamExpiredHeader = event.headers.get(IAM_SESSION_EXPIRED_HEADER);
47
- if (null !== iamExpiredHeader) {
48
- this._iamExpirationHeaderPresence.next(true);
58
+ if (isIamExpiredHeader(event) ||
59
+ isRedirectionToIamACV(event) ||
60
+ isRedirectionToCyberLogin(event)) {
61
+ this._isIamSessionExpired.next(true);
49
62
  }
50
63
  }
51
64
  return event;
52
65
  }), catchError(this.handleError.bind(this)));
53
66
  }
54
67
  handleError(err) {
68
+ console.log('err', typeof err, err);
55
69
  if (err instanceof HttpErrorResponse) {
56
- if (err.status === 200) {
57
- const isLogin = err.url.indexOf(LOGIN_PATH) > 0;
70
+ if (err.status === 200 /* Ok */) {
71
+ const isLogin = err.url.indexOf(CYBER_LOGIN_PATH) > 0;
58
72
  if (isLogin) {
59
- this._iamExpirationHeaderPresence.next(true);
73
+ this._isIamSessionExpired.next(true);
60
74
  }
61
75
  }
62
76
  }
@@ -9922,7 +9936,7 @@ class RedirectComponent {
9922
9936
  this.modalHeaderText = 'Information';
9923
9937
  this.modalBodyText = `<p>Votre session a expiré.</p>
9924
9938
  <p>Vous pouvez vous connecter à nouveau pour continuer à utiliser nos services.</p>`;
9925
- this.iamInterceptor.iamExpirationHeaderPresence
9939
+ this.iamInterceptor.isIamSessionExpired
9926
9940
  .pipe(first())
9927
9941
  .subscribe(() => this.showModal());
9928
9942
  }