zek 14.2.60 → 14.2.62
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/models/login.model.mjs +1 -1
- package/esm2020/lib/services/auth.service.mjs +49 -30
- package/esm2020/lib/utils/convert.mjs +7 -1
- package/fesm2015/zek.mjs +53 -28
- package/fesm2015/zek.mjs.map +1 -1
- package/fesm2020/zek.mjs +53 -28
- package/fesm2020/zek.mjs.map +1 -1
- package/lib/models/login.model.d.ts +2 -2
- package/lib/services/auth.service.d.ts +11 -10
- package/lib/utils/convert.d.ts +1 -0
- package/package.json +1 -1
package/fesm2020/zek.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { Injectable, InjectionToken, Inject, NgModule, Directive, Input, EventEmitter, Output, ViewChild, Pipe, Component, forwardRef, ViewEncapsulation, ChangeDetectionStrategy, Optional, HostListener } from '@angular/core';
|
|
3
3
|
import * as i1 from '@angular/router';
|
|
4
4
|
import { NavigationStart, PRIMARY_OUTLET, RouterModule } from '@angular/router';
|
|
5
|
-
import { BehaviorSubject,
|
|
5
|
+
import { BehaviorSubject, Subject, catchError, of, firstValueFrom, ReplaySubject, timer } from 'rxjs';
|
|
6
6
|
import * as i1$1 from '@ngx-translate/core';
|
|
7
7
|
import { TranslateModule } from '@ngx-translate/core';
|
|
8
8
|
import * as i1$2 from '@angular/common/http';
|
|
@@ -335,6 +335,12 @@ class Convert {
|
|
|
335
335
|
}
|
|
336
336
|
return false;
|
|
337
337
|
}
|
|
338
|
+
static parseNumber(value) {
|
|
339
|
+
if (typeof value === 'undefined' || value == null || (typeof value === 'string' && value.length === 0))
|
|
340
|
+
return null;
|
|
341
|
+
let n = Number(value);
|
|
342
|
+
return !isNaN(n) ? n : null;
|
|
343
|
+
}
|
|
338
344
|
static toNumber(value, defaultValue = 0) {
|
|
339
345
|
return this.isNumber(value) ? Number(value) : defaultValue;
|
|
340
346
|
}
|
|
@@ -1110,7 +1116,6 @@ class UrlHelper {
|
|
|
1110
1116
|
class AuthService {
|
|
1111
1117
|
constructor() {
|
|
1112
1118
|
this._isInitialized = false;
|
|
1113
|
-
this._subject = new BehaviorSubject(false); //todo check if need BehaviorSubject
|
|
1114
1119
|
this._oldValueIsAuthenticated = false;
|
|
1115
1120
|
this._user = null;
|
|
1116
1121
|
}
|
|
@@ -1118,25 +1123,45 @@ class AuthService {
|
|
|
1118
1123
|
if (!this._isInitialized) {
|
|
1119
1124
|
let tmp = StorageHelper.get('login');
|
|
1120
1125
|
if (tmp) {
|
|
1126
|
+
// let user:LoginUser = {
|
|
1127
|
+
// id: +tmp.id,
|
|
1128
|
+
// expired: DateHelper.parseDate(tmp.expired)
|
|
1129
|
+
// }
|
|
1130
|
+
tmp.id = Convert.parseNumber(tmp.id);
|
|
1121
1131
|
tmp.expired = DateHelper.parseDate(tmp.expired);
|
|
1122
1132
|
tmp.refreshTokenTime = DateHelper.parseDate(tmp.refreshTokenTime);
|
|
1123
1133
|
}
|
|
1124
1134
|
this._user = tmp;
|
|
1125
1135
|
this._isInitialized = true;
|
|
1136
|
+
this._starRefreshTokenTimer();
|
|
1126
1137
|
}
|
|
1127
1138
|
return this._user;
|
|
1128
1139
|
}
|
|
1129
|
-
|
|
1130
|
-
|
|
1140
|
+
_starRefreshTokenTimer() {
|
|
1141
|
+
this._stopRefreshTokenTimer();
|
|
1142
|
+
let user = this.user;
|
|
1143
|
+
if (user && user.refreshTokenTime) {
|
|
1144
|
+
const timeout = user.refreshTokenTime.getTime() - Date.now(); // - (60 * 1000);
|
|
1145
|
+
this._refreshTokenTimeout = setTimeout(() => {
|
|
1146
|
+
if (this._onRefreshTokenSubject) {
|
|
1147
|
+
this._onRefreshTokenSubject.next();
|
|
1148
|
+
}
|
|
1149
|
+
}, timeout);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
_stopRefreshTokenTimer() {
|
|
1153
|
+
if (typeof this._refreshTokenTimeout === 'number') {
|
|
1154
|
+
clearTimeout(this._refreshTokenTimeout);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1131
1157
|
isAuthenticated() {
|
|
1132
1158
|
let expired = this.getExpired() || new Date(0);
|
|
1133
1159
|
const newValue = new Date() < expired;
|
|
1134
|
-
if (this._oldValueIsAuthenticated
|
|
1160
|
+
if (this._oldValueIsAuthenticated !== newValue) {
|
|
1135
1161
|
this._oldValueIsAuthenticated = newValue;
|
|
1136
|
-
if (this.
|
|
1137
|
-
this.
|
|
1162
|
+
if (this._onSignedInSubject) {
|
|
1163
|
+
this._onSignedInSubject.next(newValue);
|
|
1138
1164
|
}
|
|
1139
|
-
this._subject.next(newValue);
|
|
1140
1165
|
//if user is signed in and expired we need to logout (remove from localStorage)
|
|
1141
1166
|
if (!newValue) {
|
|
1142
1167
|
this.logout();
|
|
@@ -1145,41 +1170,41 @@ class AuthService {
|
|
|
1145
1170
|
}
|
|
1146
1171
|
return newValue;
|
|
1147
1172
|
}
|
|
1148
|
-
/**
|
|
1149
|
-
* @deprecated The method should not be used. please use onSignedIn
|
|
1150
|
-
*/
|
|
1151
|
-
isSignedIn() {
|
|
1152
|
-
return this._subject.asObservable();
|
|
1153
|
-
}
|
|
1154
1173
|
get onSignedIn() {
|
|
1155
|
-
if (!this.
|
|
1156
|
-
this.
|
|
1157
|
-
this.
|
|
1174
|
+
if (!this._onSignedInSubject) {
|
|
1175
|
+
this._onSignedInSubject = new BehaviorSubject(false);
|
|
1176
|
+
this._onSignedInObservable = this._onSignedInSubject.asObservable();
|
|
1158
1177
|
}
|
|
1159
|
-
if (!this.
|
|
1160
|
-
throw new Error("
|
|
1161
|
-
return this.
|
|
1178
|
+
if (!this._onSignedInObservable)
|
|
1179
|
+
throw new Error("_onExecuteObservable is undefined");
|
|
1180
|
+
return this._onSignedInObservable;
|
|
1181
|
+
}
|
|
1182
|
+
get onRefreshToken() {
|
|
1183
|
+
if (!this._onRefreshTokenSubject) {
|
|
1184
|
+
this._onRefreshTokenSubject = new Subject();
|
|
1185
|
+
this._onRefreshTokenObservable = this._onRefreshTokenSubject.asObservable();
|
|
1186
|
+
}
|
|
1187
|
+
if (!this._onRefreshTokenObservable)
|
|
1188
|
+
throw new Error("onRefreshTokenObservable is undefined");
|
|
1189
|
+
return this._onRefreshTokenObservable;
|
|
1162
1190
|
}
|
|
1163
1191
|
login(user) {
|
|
1164
1192
|
if (user) {
|
|
1193
|
+
user.id = Convert.parseNumber(user.id);
|
|
1194
|
+
user.expired = DateHelper.parseDate(user.expired);
|
|
1195
|
+
user.refreshTokenTime = DateHelper.parseDate(user.refreshTokenTime);
|
|
1165
1196
|
if (Array.isArray(user.roles)) {
|
|
1166
1197
|
user.roles = user.roles.map(function (e) { return e.toUpperCase(); });
|
|
1167
1198
|
}
|
|
1168
1199
|
}
|
|
1169
1200
|
StorageHelper.set('login', user);
|
|
1170
1201
|
this._user = null;
|
|
1171
|
-
this._isInitialized = false;
|
|
1172
|
-
this.isAuthenticated(); //this method need to execute subject.next();
|
|
1202
|
+
this._isInitialized = false; //user get method will init user
|
|
1203
|
+
this.isAuthenticated(); //this method need to execute subject.next();
|
|
1173
1204
|
}
|
|
1174
1205
|
logout() {
|
|
1175
1206
|
this.login(null);
|
|
1176
1207
|
}
|
|
1177
|
-
// getUser(): LoginToken | null {
|
|
1178
|
-
// if (!this.model) {
|
|
1179
|
-
// this.model = StorageHelper.get('login');
|
|
1180
|
-
// }
|
|
1181
|
-
// return this.model;
|
|
1182
|
-
// }
|
|
1183
1208
|
getExpired() {
|
|
1184
1209
|
let user = this.user;
|
|
1185
1210
|
if (user) {
|