ng-ipa-library 1.2.1 → 1.2.2
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/esm2020/lib/core/interceptors/myIPAToken.interceptor.mjs +4 -53
- package/fesm2015/ng-ipa-library.mjs +3 -51
- package/fesm2015/ng-ipa-library.mjs.map +1 -1
- package/fesm2020/ng-ipa-library.mjs +3 -50
- package/fesm2020/ng-ipa-library.mjs.map +1 -1
- package/lib/core/interceptors/myIPAToken.interceptor.d.ts +2 -8
- package/package.json +1 -1
|
@@ -1,26 +1,13 @@
|
|
|
1
1
|
import { Injectable } from '@angular/core';
|
|
2
2
|
import * as i0 from "@angular/core";
|
|
3
3
|
import * as i1 from "../services/auth.service";
|
|
4
|
-
import * as i2 from "@angular/common/http";
|
|
5
|
-
import * as i3 from "../services/loader.service";
|
|
6
4
|
export class myIPATokenInterceptor {
|
|
7
|
-
constructor(authService
|
|
5
|
+
constructor(authService) {
|
|
8
6
|
this.authService = authService;
|
|
9
|
-
this.http = http;
|
|
10
|
-
this.loaderService = loaderService;
|
|
11
|
-
this.refresh = true;
|
|
12
|
-
this.loaderService.addExceptionUrl({
|
|
13
|
-
path: '/api/users?refresh',
|
|
14
|
-
method: 'GET',
|
|
15
|
-
});
|
|
16
7
|
}
|
|
17
8
|
intercept(request, next) {
|
|
18
|
-
if (this.isException(request)) {
|
|
19
|
-
return next.handle(request);
|
|
20
|
-
}
|
|
21
9
|
const token = this.authService.getTokenFromHidden();
|
|
22
10
|
if (token) {
|
|
23
|
-
this.isTokenExpired(token);
|
|
24
11
|
request = request.clone({
|
|
25
12
|
setHeaders: {
|
|
26
13
|
Authorization: `Bearer ${token}`,
|
|
@@ -29,46 +16,10 @@ export class myIPATokenInterceptor {
|
|
|
29
16
|
}
|
|
30
17
|
return next.handle(request);
|
|
31
18
|
}
|
|
32
|
-
isTokenExpired(token) {
|
|
33
|
-
const redirectPath = location.pathname;
|
|
34
|
-
const decodedToken = this.authService.getDecodedTokenFromHidden();
|
|
35
|
-
const expDate = new Date((decodedToken.exp ?? 0) * 1000);
|
|
36
|
-
if (expDate < new Date()) {
|
|
37
|
-
location.replace('/ar/login?redirect=' + redirectPath);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
if (this.authService.currentUserUrl) {
|
|
42
|
-
if (this.refresh) {
|
|
43
|
-
this.http
|
|
44
|
-
.get(this.authService.currentUserUrl + `/api/users?refresh`, {
|
|
45
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
46
|
-
})
|
|
47
|
-
.subscribe((user) => {
|
|
48
|
-
localStorage.setItem('token', user.token);
|
|
49
|
-
this.refresh = false;
|
|
50
|
-
setTimeout(() => {
|
|
51
|
-
this.refresh = true;
|
|
52
|
-
}, 60 * 1000);
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
throw new Error("provide current base user api url using this function authService.setCurrentUserUrl('https://...')");
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
isException(request) {
|
|
62
|
-
if (request.url.includes('/api/users?refresh') &&
|
|
63
|
-
request.method === 'GET') {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
19
|
}
|
|
69
|
-
myIPATokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: myIPATokenInterceptor, deps: [{ token: i1.AuthService }
|
|
20
|
+
myIPATokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: myIPATokenInterceptor, deps: [{ token: i1.AuthService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
70
21
|
myIPATokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: myIPATokenInterceptor });
|
|
71
22
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: myIPATokenInterceptor, decorators: [{
|
|
72
23
|
type: Injectable
|
|
73
|
-
}], ctorParameters: function () { return [{ type: i1.AuthService }
|
|
74
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
24
|
+
}], ctorParameters: function () { return [{ type: i1.AuthService }]; } });
|
|
25
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibXlJUEFUb2tlbi5pbnRlcmNlcHRvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3Byb2plY3RzL25nLWlwYS1saWJyYXJ5L3NyYy9saWIvY29yZS9pbnRlcmNlcHRvcnMvbXlJUEFUb2tlbi5pbnRlcmNlcHRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sZUFBZSxDQUFDOzs7QUFXM0MsTUFBTSxPQUFPLHFCQUFxQjtJQUNoQyxZQUFvQixXQUF3QjtRQUF4QixnQkFBVyxHQUFYLFdBQVcsQ0FBYTtJQUFHLENBQUM7SUFFaEQsU0FBUyxDQUNQLE9BQTZCLEVBQzdCLElBQWlCO1FBRWpCLE1BQU0sS0FBSyxHQUFHLElBQUksQ0FBQyxXQUFXLENBQUMsa0JBQWtCLEVBQUUsQ0FBQztRQUNwRCxJQUFJLEtBQUssRUFBRTtZQUNULE9BQU8sR0FBRyxPQUFPLENBQUMsS0FBSyxDQUFDO2dCQUN0QixVQUFVLEVBQUU7b0JBQ1YsYUFBYSxFQUFFLFVBQVUsS0FBSyxFQUFFO2lCQUNqQzthQUNGLENBQUMsQ0FBQztTQUNKO1FBQ0QsT0FBTyxJQUFJLENBQUMsTUFBTSxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQzlCLENBQUM7O2tIQWhCVSxxQkFBcUI7c0hBQXJC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Xh0LmhhbmRsZShyZXF1ZXN0KTtcclxuICB9XHJcbn1cclxuIl19
|
|
@@ -1417,23 +1417,12 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImpor
|
|
|
1417
1417
|
}], ctorParameters: function () { return [{ type: AuthService }, { type: i2$4.HttpClient }, { type: LoaderService }]; } });
|
|
1418
1418
|
|
|
1419
1419
|
class myIPATokenInterceptor {
|
|
1420
|
-
constructor(authService
|
|
1420
|
+
constructor(authService) {
|
|
1421
1421
|
this.authService = authService;
|
|
1422
|
-
this.http = http;
|
|
1423
|
-
this.loaderService = loaderService;
|
|
1424
|
-
this.refresh = true;
|
|
1425
|
-
this.loaderService.addExceptionUrl({
|
|
1426
|
-
path: '/api/users?refresh',
|
|
1427
|
-
method: 'GET',
|
|
1428
|
-
});
|
|
1429
1422
|
}
|
|
1430
1423
|
intercept(request, next) {
|
|
1431
|
-
if (this.isException(request)) {
|
|
1432
|
-
return next.handle(request);
|
|
1433
|
-
}
|
|
1434
1424
|
const token = this.authService.getTokenFromHidden();
|
|
1435
1425
|
if (token) {
|
|
1436
|
-
this.isTokenExpired(token);
|
|
1437
1426
|
request = request.clone({
|
|
1438
1427
|
setHeaders: {
|
|
1439
1428
|
Authorization: `Bearer ${token}`,
|
|
@@ -1442,49 +1431,12 @@ class myIPATokenInterceptor {
|
|
|
1442
1431
|
}
|
|
1443
1432
|
return next.handle(request);
|
|
1444
1433
|
}
|
|
1445
|
-
isTokenExpired(token) {
|
|
1446
|
-
var _a;
|
|
1447
|
-
const redirectPath = location.pathname;
|
|
1448
|
-
const decodedToken = this.authService.getDecodedTokenFromHidden();
|
|
1449
|
-
const expDate = new Date(((_a = decodedToken.exp) !== null && _a !== void 0 ? _a : 0) * 1000);
|
|
1450
|
-
if (expDate < new Date()) {
|
|
1451
|
-
location.replace('/ar/login?redirect=' + redirectPath);
|
|
1452
|
-
return;
|
|
1453
|
-
}
|
|
1454
|
-
else {
|
|
1455
|
-
if (this.authService.currentUserUrl) {
|
|
1456
|
-
if (this.refresh) {
|
|
1457
|
-
this.http
|
|
1458
|
-
.get(this.authService.currentUserUrl + `/api/users?refresh`, {
|
|
1459
|
-
headers: { Authorization: `Bearer ${token}` },
|
|
1460
|
-
})
|
|
1461
|
-
.subscribe((user) => {
|
|
1462
|
-
localStorage.setItem('token', user.token);
|
|
1463
|
-
this.refresh = false;
|
|
1464
|
-
setTimeout(() => {
|
|
1465
|
-
this.refresh = true;
|
|
1466
|
-
}, 60 * 1000);
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
else {
|
|
1471
|
-
throw new Error("provide current base user api url using this function authService.setCurrentUserUrl('https://...')");
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
isException(request) {
|
|
1476
|
-
if (request.url.includes('/api/users?refresh') &&
|
|
1477
|
-
request.method === 'GET') {
|
|
1478
|
-
return true;
|
|
1479
|
-
}
|
|
1480
|
-
return false;
|
|
1481
|
-
}
|
|
1482
1434
|
}
|
|
1483
|
-
myIPATokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: myIPATokenInterceptor, deps: [{ token: AuthService }
|
|
1435
|
+
myIPATokenInterceptor.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: myIPATokenInterceptor, deps: [{ token: AuthService }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1484
1436
|
myIPATokenInterceptor.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: myIPATokenInterceptor });
|
|
1485
1437
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.2", ngImport: i0, type: myIPATokenInterceptor, decorators: [{
|
|
1486
1438
|
type: Injectable
|
|
1487
|
-
}], ctorParameters: function () { return [{ type: AuthService }
|
|
1439
|
+
}], ctorParameters: function () { return [{ type: AuthService }]; } });
|
|
1488
1440
|
|
|
1489
1441
|
class BreadcrumbsService {
|
|
1490
1442
|
constructor() { }
|