import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { inject } from '@angular/core';
import { tap } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class AuthService {

  httpClient = inject(HttpClient);
  baseUrl = 'https://api.reverify.org/v1';
  constructor() { }
  signup(data: any) {
    return this.httpClient.post(`${this.baseUrl}/register.php`, data);
  }
  login(data: any) {
    return this.httpClient.post(`${this.baseUrl}/login.php`, data)
      .pipe(tap((result) => {
        localStorage.setItem('authUser', JSON.stringify(result));
      }));
  }
  logout() {
    localStorage.removeItem('authUser');
  }
  isLoggedIn() {
    return localStorage.getItem('authUser') !== null;
  }
}
