bstlboard-front/src/app/services/auth.service.ts

38 lines
881 B
TypeScript

import { Injectable } from '@angular/core';
import { ReplaySubject, of } from 'rxjs';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from './../../environments/environment';
@Injectable({
providedIn: 'root',
})
export class AuthService {
auth: ReplaySubject<any> = new ReplaySubject(undefined);
constructor(private http: HttpClient) {
}
getAuth() {
return this.authMe().toPromise().then((data: any) => {
this.auth.next(data);
return data;
}, error => {
throw new Error(error);
});
}
authMe() {
return this.http.get(environment.apiUrl + "/auth");
}
getExternal() {
return this.http.get(environment.apiUrl + "/auth/external");
}
logout() {
return this.http.post(environment.apiUrl + "/logout", {});
}
}