auth.service.ts 673 B

1234567891011121314151617
  1. import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
  2. import { Injectable } from '@angular/core';
  3. import { Observable, throwError } from 'rxjs';
  4. import { catchError, tap } from 'rxjs/operators';
  5. @Injectable({ providedIn: 'root' })
  6. export class AuthService {
  7. private loginUrl = 'http://localhost:8080/login'; // Replace with your server login URL
  8. constructor(private http: HttpClient) { }
  9. login(username: string, password: string) {
  10. const headers = new HttpHeaders({ Authorization: 'Basic ' + btoa(username + ':' + password) });
  11. console.log("logged in service");
  12. return this.http.post(this.loginUrl, {}, { headers });
  13. }
  14. }