mirror of
https://github.com/Eugeny/tabby-web.git
synced 2026-08-19 07:46:03 +01:00
.
This commit is contained in:
30
frontend/src/services/login.service.ts
Normal file
30
frontend/src/services/login.service.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { AsyncSubject } from 'rxjs'
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { User } from '../api'
|
||||
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class LoginService {
|
||||
user: User
|
||||
ready$ = new AsyncSubject<void>()
|
||||
|
||||
constructor (private http: HttpClient) {
|
||||
this.init()
|
||||
}
|
||||
|
||||
async updateUser () {
|
||||
await this.http.put('/api/1/user', this.user).toPromise()
|
||||
}
|
||||
|
||||
private async init () {
|
||||
try {
|
||||
this.user = await this.http.get('/api/1/user').toPromise()
|
||||
} catch {
|
||||
this.user = null
|
||||
}
|
||||
|
||||
this.ready$.next()
|
||||
this.ready$.complete()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user