Fix: Save account error was because in constructor type did not end in underscore

Fix: Employee save as checking for in None instead of is None

Feature: Checking the existing token for validity in constructor of auth service, this should prevent last login showing
Feature: Moved the middleware secret key into the env file

Chore: Replaced my own GUID() with postgres UUID() type
This commit is contained in:
2020-06-30 11:32:09 +05:30
parent 6ccb3634be
commit ad8a2d2cc3
19 changed files with 132 additions and 171 deletions

View File

@ -16,12 +16,28 @@ export class AuthService {
public currentUser: Observable<User>;
constructor(private http: HttpClient) {
this.currentUserSubject = new BehaviorSubject<User>(JSON.parse(localStorage.getItem(JWT_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);
} else {
this.currentUserSubject = new BehaviorSubject<User>(existingToken);
}
this.currentUser = this.currentUserSubject.asObservable();
}
public get user(): User {
return this.currentUserSubject.value;
const val = this.currentUserSubject.value;
if (val == null) {
return val;
}
const expired = Date.now() > val.exp * 1000;
if (expired) {
this.logout();
return null;
} else {
return this.currentUserSubject.value;
}
}
login(username: string, password: string, otp: string) {

View File

@ -60,7 +60,7 @@ export class LoginComponent implements OnInit, AfterViewInit {
this.router.navigate([this.returnUrl]);
},
(error) => {
if (error.status === 401 && 'Client is not registered' == error.error.detail) {
if (error.status === 401 && 'Client is not registered' === error.error.detail) {
this.showOtp = true;
this.clientId = this.cs.getCookie('client_id');
}