ChatGPT Найди ошибку
import { Student } from './../models/students';
import { map, Observable } from 'rxjs';
import { User } from './../models/user';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class AuthServiceService {
constructor(private http: HttpClient) { }
auth(loginAndPass: String) {
this.login(loginAndPass).subscribe(
res => {console.log(res);},
// err => {console.log(err.message);},
)
}
login(loginAndPass: String): Observable<unknown> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Basic ' + loginAndPass,
})
};
return this.http.post<User>('api/login', null, httpOptions).pipe(
map(data => { localStorage.setItem('currentUser', JSON.stringify(data)) })
);
}
logout() {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
return this.http.post<User>('api/logout', null, httpOptions).subscribe(
res => {console.log(res);},
)
}
}
import { Student } from './../models/students';
import { map, Observable } from 'rxjs';
import { User } from './../models/user';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class AuthServiceService {
constructor(private http: HttpClient) { }
auth(loginAndPass: String) {
this.login(loginAndPass).subscribe(
res => {console.log(res);},
// err => {console.log(err.message);},
)
}
login(loginAndPass: String): Observable<unknown> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': 'Basic ' + loginAndPass,
})
};
return this.http.post<User>('api/login', null, httpOptions).pipe(
map(data => { localStorage.setItem('currentUser', JSON.stringify(data)) })
);
}
logout() {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
};
return this.http.post<User>('api/logout', null, httpOptions).subscribe(
res => {console.log(res);},
)
}
}