Files
tabby-web/frontend/src/common/services/login.service.ts

31 lines
690 B
TypeScript
Raw Normal View History

2021-06-21 09:22:13 +02:00
import { AsyncSubject } from 'rxjs'
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
2021-09-16 23:36:51 +02:00
import { User } from '../../api'
2021-06-21 09:22:13 +02:00
@Injectable({ providedIn: 'root' })
export class LoginService {
2021-06-25 21:55:40 +02:00
user: User
2021-06-21 09:22:13 +02:00
ready$ = new AsyncSubject<void>()
constructor (private http: HttpClient) {
this.init()
}
2021-06-25 21:55:40 +02:00
async updateUser () {
await this.http.put('/api/1/user', this.user).toPromise()
}
2021-06-21 09:22:13 +02:00
private async init () {
2021-06-25 21:55:40 +02:00
try {
this.user = await this.http.get('/api/1/user').toPromise()
} catch {
this.user = null
}
2021-06-21 09:22:13 +02:00
this.ready$.next()
this.ready$.complete()
}
}