Skip to content

Commit

Permalink
Comment Auth Service Calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanvicente committed Jan 29, 2024
1 parent bfe46ec commit 41d3d61
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
22 changes: 9 additions & 13 deletions src/app/interceptors/jwt-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,23 @@ export class JwtInterceptor implements HttpInterceptor {

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

const currentUser = this.authService.currentUser;
const isLoggedIn = currentUser && currentUser.token;
const isApiUrl = request.url.startsWith(environment.BACKEND_ITA_SSO_BASE_URL);

console.log('***************************');
console.log(currentUser);
console.log(isLoggedIn);
console.log(isApiUrl);



console.log('***************************INTERCEPTOR');



/* const currentUser = this.authService.currentUser;
const isLoggedIn = currentUser && currentUser.token;
const isApiUrl = request.url.startsWith(environment.BACKEND_ITA_SSO_BASE_URL);*/

/* console.log(currentUser);
console.log(isLoggedIn);
console.log(isApiUrl);*/

if (isLoggedIn && isApiUrl) {
/* if (isLoggedIn && isApiUrl) {
request = request.clone({
setHeaders: { Authorization: `Bearer ${currentUser.token}` }
});
}
}*/

return next.handle(request);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/modals/login-modal/login-modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class LoginModalComponent {

console.log('*************', this.loginForm)

this.authService.login(dni, password).subscribe({
/* this.authService.login(dni, password).subscribe({
next: (userData) => {
console.log(userData, "login")
// actions like redirecting user to another page
Expand All @@ -55,7 +55,7 @@ export class LoginModalComponent {
// this.router.navigateByUrl('/')
this.closeModal();
}
});
});*/

}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export class RegisterModalComponent {
user.itineraryId = environment.ITINERARY_ID;

console.log('from register-modal********', user)
this.authService.register(user).subscribe({
/* this.authService.register(user).subscribe({
next: (userData) => {console.log('userData ' , userData)},
error: (errorData) => {
console.error("Error during registration", errorData);
this.registerError = errorData.error || 'Error en el registro'; // Accede a la propiedad error de HttpErrorResponse
},
});
});*/
}
this.closeModal();
}
Expand Down
14 changes: 7 additions & 7 deletions src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import { Router } from "@angular/router";
@Injectable()
export class AuthService {

private userSubject: BehaviorSubject<User>;
public user: Observable<User>;
/* private userSubject: BehaviorSubject<User>;
public user: Observable<User>;*/

constructor(private http: HttpClient, private router: Router) {
this.userSubject = new BehaviorSubject(JSON.parse(localStorage.getItem("user")!));
//this.userSubject = new BehaviorSubject(JSON.parse(localStorage.getItem("user")!));

console.log("*******"+JSON.stringify(this.userSubject));
this.user = this.userSubject.asObservable();
//console.log("*******"+JSON.stringify(this.userSubject));
//this.user = this.userSubject.asObservable();
}

public get currentUser(): User {
/*public get currentUser(): User {
return this.userSubject.value;
}
Expand Down Expand Up @@ -125,5 +125,5 @@ export class AuthService {
public getExpiration() {
const expiration = localStorage.getItem("expires_at");
return expiration != null ? JSON.parse(expiration) : null;
}
}*/
}

0 comments on commit 41d3d61

Please sign in to comment.