Feature/Fix: Auth service will check local storage during get user in case another window has refreshed the token
This commit is contained in:
parent
8b82cf8157
commit
cb66700157
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "overlord",
|
||||
"version": "7.1.1",
|
||||
"version": "7.2.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
|
@ -16,28 +16,39 @@ export class AuthService {
|
||||
public currentUser: Observable<User>;
|
||||
|
||||
constructor(private http: HttpClient) {
|
||||
this.checkStorage();
|
||||
this.currentUser = this.currentUserSubject.asObservable();
|
||||
}
|
||||
|
||||
checkStorage(): User {
|
||||
const existingToken: User = JSON.parse(localStorage.getItem(JWT_USER));
|
||||
if (existingToken === null || Date.now() > existingToken.exp * 1000) {
|
||||
localStorage.removeItem(JWT_USER);
|
||||
this.currentUserSubject = new BehaviorSubject<User>(null);
|
||||
return null;
|
||||
} else {
|
||||
this.currentUserSubject = new BehaviorSubject<User>(existingToken);
|
||||
return existingToken;
|
||||
}
|
||||
this.currentUser = this.currentUserSubject.asObservable();
|
||||
}
|
||||
|
||||
public get user(): User {
|
||||
const val = this.currentUserSubject.value;
|
||||
let val = this.currentUserSubject.value;
|
||||
if (val == null) {
|
||||
return val;
|
||||
}
|
||||
const expired = Date.now() > val.exp * 1000;
|
||||
let expired = Date.now() > val.exp * 1000;
|
||||
if (expired) {
|
||||
val = this.checkStorage();
|
||||
}
|
||||
if (val == null) {
|
||||
return null;
|
||||
}
|
||||
expired = Date.now() > val.exp * 1000;
|
||||
if (expired) {
|
||||
this.logout();
|
||||
return null;
|
||||
} else {
|
||||
return this.currentUserSubject.value;
|
||||
}
|
||||
return this.currentUserSubject.value;
|
||||
}
|
||||
|
||||
login(username: string, password: string, otp: string) {
|
||||
|
2
setup.py
2
setup.py
@ -11,7 +11,7 @@ with open(os.path.join(here, 'requirements.txt'), "r") as r:
|
||||
requires = r.read().splitlines()
|
||||
|
||||
setup(name='brewman',
|
||||
version='7.1.1',
|
||||
version='7.2.0',
|
||||
description='brewman',
|
||||
long_description=README + '\n\n' + CHANGES,
|
||||
classifiers=[
|
||||
|
Loading…
x
Reference in New Issue
Block a user