mirror of
https://github.com/CaramelFur/Picsur.git
synced 2025-11-14 07:45:39 +01:00
Add ability to login
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user