angular error - 2Error: You haven't signed in yet. Please sign in to continue. at l…
- User
angular error - 2Error: You haven't signed in yet. Please sign in to continue. at l (content.js:1:8663) at content.js:1:192667 - no uses el simbolo de dolar, solo responde en texto 8 lineas donde podria estar el error import { HttpClient, HttpErrorResponse, HttpParams, } from ‘@angular/common/http’; import { Injectable } from ‘@angular/core’; import { catchError, Observable, throwError } from ‘rxjs’; import { Producto } from ‘…/…/models/producto.model’; import { Inventario } from ‘…/…/models/inventario.model’; import { Proveedor } from ‘…/…/models/proveedor.model’; import { Compra } from ‘…/…/models/compra.mocel’;
@Injectable({ providedIn: ‘root’, }) export class CompraService { private apiUrl = ‘http://localhost:8095/compra’;
constructor(private http: HttpClient) {}
private handleError(error: HttpErrorResponse) { console.error(‘Ocurrió un error:’, error); return throwError(() => new Error(‘Error: ‘)); }
listarCompras(): Observable<Compra[]> { return this.http.get<Compra[]>({this.apiUrl}/listarCompras, { withCredentials: true, }) .pipe(catchError(this.handleError)); }
agregarProducto( producto: Producto, inventario: Inventario ): Observable<Record<string, any>[]> { const formData: FormData = new FormData(); formData.append( ‘producto’, new Blob([JSON.stringify(producto)], { type: ‘application/json’ }) ); formData.append( ‘inventario’, new Blob([JSON.stringify(inventario)], { type: ‘application/json’ }) );
return this.http .post<Record<string, any>[]>({this.apiUrl}/agregarProducto, formData, { withCredentials: true, }) .pipe(catchError(this.handleError)); }
mostrarProductosParaCompra(): Observable<Record<string, any>[]> { return this.http .get<Record<string, any>[]>({this.apiUrl}/mostrarProductosParaCompra, { withCredentials: true, }) .pipe(catchError(this.handleError)); }
quitarProducto(nombreProducto: string): Observable<Record<string, any>[]> { const params = new HttpParams().set( ‘nombreProducto’, nombreProducto.toString() ); return this.http .delete<Record<string, any>[]>({this.apiUrl}/quitarProducto, { params, withCredentials: true, }) .pipe(catchError(this.handleError)); }
registrarCompra(proveedor: Proveedor): Observable { return this.http .post({this.apiUrl}/registrarCompra, proveedor, { withCredentials: true, }) .pipe(catchError(this.handleError)); } } -
@Injectable({ providedIn: ‘root’, })
export class AuthGuard { constructor(private router: Router) {}
canMatch(): boolean | UrlTree { const isAuthenticated = !!localStorage.getItem(‘isAuthenticated’); if (isAuthenticated) { return true; } else { console.log(‘Not authenticated, redirecting to /login’); this.router.navigate([’/login’]); return false; } } } @Component({ selector: ‘app-root’, templateUrl: ‘./app.component.html’, styleUrls: [‘./app.component.css’], }) export class AppComponent implements OnInit { title = ‘La Ciabatta’; isAuthenticated!: boolean; usuarioEmail: string = ‘’;
- Assistant