Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Aug 29, 2024
1 parent 2437698 commit ebd55a9
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 31 deletions.
1 change: 0 additions & 1 deletion frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ActivatedRouteSnapshot, ResolveFn, RouterModule, Routes } from '@angula
import { OverviewComponent } from './overview/overview.component';
import { EMPTY, of } from 'rxjs';
import { SidepanelComponent } from './shared/custom/sidepanel/sidepanel.component';
import { authGuard } from './shared/guards/auth.guard';
import { AutoLoginPartialRoutesGuard } from 'angular-auth-oidc-client';
import { CallbackComponent } from './callback/callback.component';

Expand Down
6 changes: 2 additions & 4 deletions frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { OidcSecurityService } from 'angular-auth-oidc-client';

@Component({
Expand All @@ -10,8 +10,6 @@ import { OidcSecurityService } from 'angular-auth-oidc-client';
export class AppComponent implements OnInit {
constructor(private oidcSecurityService: OidcSecurityService) {}
ngOnInit(): void {
this.oidcSecurityService
.checkAuth()
.subscribe(({ isAuthenticated, userData, accessToken, idToken, configId }) => {});
this.oidcSecurityService.checkAuth().subscribe();
}
}
2 changes: 1 addition & 1 deletion frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export const MY_FORMATS = {
deps: [MAT_DATE_LOCALE],
},
{ provide: MAT_DATE_FORMATS, useValue: MY_FORMATS },
{ provide: HTTP_INTERCEPTORS, useClass: OauthInterceptor, multi: true },
// { provide: HTTP_INTERCEPTORS, useClass: OauthInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
// { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ export class ApplicationTopBarComponent implements OnInit, OnDestroy {
}

username() {
return this.oauthService.getUserData().pipe(
map((user) => user?.name || 'No username available'),
switchMap((username) => (username ? of(username) : of('no username received'))),
);
return this.oauthService.getUserData().pipe(map((user) => user?.name || ''));
}

openTeamManagement() {
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/app/callback/callback.component.cy.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ export class KeyResultFormComponent implements OnInit {
]);

this.users$.subscribe((users) => {
const loggedInUser = this.getUserName();
users.forEach((user) => {
if (user.firstname + ' ' + user.lastname === loggedInUser) {
this.keyResultForm.controls['owner'].setValue(user);
}
});
this.getUserName().subscribe(userName =>{
users.forEach((user) => {
if (user.firstname + ' ' + user.lastname === userName) {
this.keyResultForm.controls['owner'].setValue(user);
}
});
})
});
}

Expand Down Expand Up @@ -131,7 +132,6 @@ export class KeyResultFormComponent implements OnInit {
updateFormValidity() {}

getUserName() {
// return this.oauthService.getUserData()['name'];
return '';
return this.oauthService.getUserData().pipe(map((user) => user?.name || ''));
}
}
8 changes: 3 additions & 5 deletions frontend/src/app/shared/guards/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ import { inject } from '@angular/core';
import { OidcSecurityService } from 'angular-auth-oidc-client';
import { map, take } from 'rxjs';


//Not used, can be deleted
export const authGuard: CanActivateFn = (route, state) => {
const oidcSecurityService = inject(OidcSecurityService);
const router = inject(Router);

return oidcSecurityService.isAuthenticated$.pipe(
take(1),
map(({ isAuthenticated }) => {
// allow navigation if authenticated
if (isAuthenticated) {
return true;
}
return isAuthenticated

// redirect if not authenticated
return router.parseUrl('/unauthorized');
}),
);
};
2 changes: 1 addition & 1 deletion frontend/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const environment = {
oauth: {
decreaseExpirationBySec: 30,
clearHashAfterLogin: true,
secureRoutes: ['**', 'http://localhost:4200/', 'http://localhost:8080/', 'localhost:8080/'],
secureRoutes: ['**', 'http://localhost:4200/', 'http://localhost:8080/', 'localhost:8080/', window.location.origin],
authority: 'https://sso.puzzle.ch/auth/realms/pitc',
strictDiscoveryDocumentValidation: false,
customQueryParams: { response_modes_supported: ['query'] },
Expand Down

0 comments on commit ebd55a9

Please sign in to comment.