Add ability to login

This commit is contained in:
rubikscraft
2022-03-03 15:44:22 +01:00
parent e0230b26ae
commit 9f8cf14807
10 changed files with 138 additions and 23 deletions

View File

@@ -23,10 +23,18 @@ import { KeyService } from './key.service';
providedIn: 'root',
})
export class UserService {
public get user() {
public get liveUser() {
return this.userSubject;
}
public get user() {
return this.userSubject.getValue();
}
public get isLoggedIn() {
return this.userSubject.getValue() !== null;
}
private userSubject = new BehaviorSubject<EUser | null>(null);
constructor(private api: ApiService, private key: KeyService) {
@@ -74,6 +82,7 @@ export class UserService {
const user = await this.extractUser(apikey);
if (HasFailed(user)) {
console.warn(user.getReason());
await this.logout();
return;
}
@@ -82,6 +91,7 @@ export class UserService {
const fetchedUser = await this.fetchUser();
if (HasFailed(fetchedUser)) {
console.warn(fetchedUser.getReason());
await this.logout();
return;
}