auth.service.ts 862 B

1234567891011121314151617181920212223242526272829
  1. import { Injectable } from '@angular/core';
  2. import {HttpClient, HttpHeaders} from '@angular/common/http';
  3. import {LoginInfo} from './login-info';
  4. import {Observable} from 'rxjs';
  5. import {JwtResponse} from './jwt-response';
  6. import {SignupInfo} from './signup-info';
  7. const httpOptions = {
  8. headers: new HttpHeaders({'Content-Type': 'application/json'})
  9. };
  10. @Injectable({
  11. providedIn: 'root'
  12. })
  13. export class AuthService {
  14. private loginUrl = 'http://localhost:8085/auth/signin';
  15. private signupUrl = 'http://localhost:8085/auth/signup';
  16. constructor(private http: HttpClient) { }
  17. attemptAuth(credentials: LoginInfo): Observable<JwtResponse> {
  18. return this.http.post<JwtResponse>(this.loginUrl, credentials, httpOptions);
  19. }
  20. signUp(info: SignupInfo): Observable<string> {
  21. return this.http.post<string>(this.signupUrl, info, httpOptions);
  22. }
  23. }