Added login UI
- Added empty adminui component - Added authStore
This commit is contained in:
40
frontend/src/store/authStore.ts
Normal file
40
frontend/src/store/authStore.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
interface AuthStoreState {
|
||||
username: string;
|
||||
token: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class AuthStore {
|
||||
private state: BehaviorSubject<AuthStoreState> = new BehaviorSubject<AuthStoreState>({
|
||||
username: "",
|
||||
token: "",
|
||||
});
|
||||
|
||||
// Getter for username
|
||||
get username$() {
|
||||
return this.state.asObservable().pipe(map(state => state.username));
|
||||
}
|
||||
|
||||
// Getter for token
|
||||
get token$() {
|
||||
return this.state.asObservable().pipe(map(state => state.token));
|
||||
}
|
||||
|
||||
// Mutation for username
|
||||
setUsername(username: string) {
|
||||
const currentState = this.state.getValue();
|
||||
this.state.next({ ...currentState, username });
|
||||
}
|
||||
|
||||
// Mutation for token
|
||||
setToken(token: string) {
|
||||
const currentState = this.state.getValue();
|
||||
this.state.next({ ...currentState, token });
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user