Skip to content

Commit 5178c82

Browse files
Fix linting errors
1 parent d5ffbd3 commit 5178c82

File tree

11 files changed

+59
-60
lines changed

11 files changed

+59
-60
lines changed

src/app/app-menu.component.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Component } from '@angular/core';
1+
import { Component, inject } from '@angular/core';
22
import { Observable } from 'rxjs';
33

44
import { AuthService } from './core/auth.service';
55

66
@Component({
7-
selector: 'app-menu',
8-
template: `<nav class="navbar navbar-expand-sm navbar-light bg-light">
7+
selector: 'app-menu',
8+
template: `<nav class="navbar navbar-expand-sm navbar-light bg-light">
99
<ul class="navbar-nav mr-auto">
1010
<li class="nav-item">
1111
<a class="nav-link" routerLinkActive="active" routerLink="basics/home">Home</a>
@@ -40,25 +40,27 @@ import { AuthService } from './core/auth.service';
4040
<button href="#" (click)="logout()" class="btn btn-link">(log out)</button>
4141
}
4242
</nav>`,
43-
standalone: false
43+
standalone: false
4444
})
4545
export class AppMenuComponent {
46+
private authService = inject(AuthService);
47+
4648
isAuthenticated$: Observable<boolean>;
4749

48-
constructor(private authService: AuthService) {
49-
this.isAuthenticated$ = authService.isAuthenticated$;
50+
constructor() {
51+
this.isAuthenticated$ = this.authService.isAuthenticated$;
5052
}
5153

5254
login() {
53-
this.authService.login();
54-
}
55+
this.authService.login();
56+
}
5557
logout() {
56-
this.authService.logout();
57-
}
58+
this.authService.logout();
59+
}
5860

5961
get email(): string {
6062
return this.authService.identityClaims
61-
? (this.authService.identityClaims as any)['email']
62-
: '-';
63+
? (this.authService.identityClaims as any)['email']
64+
: '-';
6365
}
6466
}

src/app/app.component.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* eslint-disable brace-style */
22
/* eslint-disable max-len */
33

4-
import { Component } from '@angular/core';
4+
import { Component, inject } from '@angular/core';
55
import { Observable } from 'rxjs';
66

77
import { AuthService } from './core/auth.service';
88

99
@Component({
10-
selector: 'app-root',
11-
template: `<div class="container-fluid">
10+
selector: 'app-root',
11+
template: `<div class="container-fluid">
1212
<app-menu></app-menu>
1313
<div class="container-fluid mt-2">
1414
<h1>Welcome</h1>
@@ -41,16 +41,16 @@ import { AuthService } from './core/auth.service';
4141
</table>
4242
</div>
4343
</div>`,
44-
standalone: false
44+
standalone: false
4545
})
4646
export class AppComponent {
47+
private authService = inject(AuthService);
48+
4749
isAuthenticated$: Observable<boolean>;
4850
isDoneLoading$: Observable<boolean>;
4951
canActivateProtectedRoutes$: Observable<boolean>;
5052

51-
constructor(
52-
private authService: AuthService,
53-
) {
53+
constructor() {
5454
this.isAuthenticated$ = this.authService.isAuthenticated$;
5555
this.isDoneLoading$ = this.authService.isDoneLoading$;
5656
this.canActivateProtectedRoutes$ = this.authService.canActivateProtectedRoutes$;

src/app/core/auth-guard-with-forced-login.service.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
33
import { Observable } from 'rxjs';
44
import { filter, switchMap, tap } from 'rxjs/operators';
@@ -7,11 +7,8 @@ import { AuthService } from './auth.service';
77

88
@Injectable()
99
export class AuthGuardWithForcedLogin {
10+
private authService = inject(AuthService);
1011

11-
constructor(
12-
private authService: AuthService,
13-
) {
14-
}
1512

1613
canActivate(
1714
route: ActivatedRouteSnapshot,

src/app/core/auth-guard.service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable } from '@angular/core';
1+
import { Injectable, inject } from '@angular/core';
22
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
33
import { Observable } from 'rxjs';
44
import { tap } from 'rxjs/operators';
@@ -7,9 +7,7 @@ import { AuthService } from './auth.service';
77

88
@Injectable()
99
export class AuthGuard {
10-
constructor(
11-
private authService: AuthService,
12-
) { }
10+
private authService = inject(AuthService);
1311

1412
canActivate(
1513
route: ActivatedRouteSnapshot,

src/app/core/auth.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
/* eslint-disable brace-style */
22

3-
import { Injectable } from '@angular/core';
3+
import { Injectable, inject } from '@angular/core';
44
import { Router } from '@angular/router';
55
import { OAuthErrorEvent, OAuthService } from 'angular-oauth2-oidc';
66
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
77
import { filter, map } from 'rxjs/operators';
88

99
@Injectable({ providedIn: 'root' })
1010
export class AuthService {
11+
private oauthService = inject(OAuthService);
12+
private router = inject(Router);
13+
1114

1215
private isAuthenticatedSubject$ = new BehaviorSubject<boolean>(false);
1316
public isAuthenticated$ = this.isAuthenticatedSubject$.asObservable();
@@ -35,10 +38,7 @@ export class AuthService {
3538
this.router.navigateByUrl('/should-login');
3639
}
3740

38-
constructor(
39-
private oauthService: OAuthService,
40-
private router: Router,
41-
) {
41+
constructor() {
4242
// Useful for debugging:
4343
this.oauthService.events.subscribe(event => {
4444
if (event instanceof OAuthErrorEvent) {

src/app/core/core.module.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
2-
import { ModuleWithProviders, NgModule, Optional, SkipSelf, inject, provideAppInitializer } from '@angular/core';
2+
import { ModuleWithProviders, NgModule, inject, provideAppInitializer } from '@angular/core';
33
import { AuthConfig, OAuthModule, OAuthModuleConfig, OAuthStorage } from 'angular-oauth2-oidc';
44
import { authAppInitializerFactory } from './auth-app-initializer.factory';
55
import { authConfig } from './auth-config';
@@ -37,7 +37,9 @@ export class CoreModule {
3737
};
3838
}
3939

40-
constructor(@Optional() @SkipSelf() parentModule: CoreModule) {
40+
constructor() {
41+
const parentModule = inject(CoreModule, { optional: true, skipSelf: true });
42+
4143
if (parentModule) {
4244
throw new Error('CoreModule is already loaded. Import it in the AppModule only');
4345
}

src/app/feature-basics/admin1.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { Observable } from 'rxjs';
33

44
import { ApiService } from '../shared/api.service';
55

66
@Component({
7-
selector: 'app-admin',
8-
template: `<p class="alert alert-danger">
7+
selector: 'app-admin',
8+
template: `<p class="alert alert-danger">
99
This is the <strong>⚙ ADMIN</strong> component.
1010
It will not redirect you to the login server.
1111
- {{ apiResponse | async }}
1212
</p>`,
13-
standalone: false
13+
standalone: false
1414
})
1515
export class Admin1Component implements OnInit {
16-
apiResponse!: Observable<string>;
16+
private apiService = inject(ApiService);
1717

18-
constructor(private apiService: ApiService) { }
18+
apiResponse!: Observable<string>;
1919

2020
ngOnInit() {
2121
this.apiResponse = this.apiService.getProtectedApiResponse();

src/app/feature-basics/home.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { Observable } from 'rxjs';
33

44
import { ApiService } from '../shared/api.service';
55

66
@Component({
7-
selector: 'app-home',
8-
template: `<p class="alert alert-primary">
7+
selector: 'app-home',
8+
template: `<p class="alert alert-primary">
99
This is the <strong>🏠 HOME</strong> component.
1010
- {{ apiResponse | async }}
1111
</p>`,
12-
standalone: false
12+
standalone: false
1313
})
1414
export class HomeComponent implements OnInit {
15-
apiResponse!: Observable<string>;
15+
private apiService = inject(ApiService);
1616

17-
constructor(private apiService: ApiService) { }
17+
apiResponse!: Observable<string>;
1818

1919
ngOnInit() {
2020
this.apiResponse = this.apiService.getProtectedApiResponse();

src/app/feature-extras/admin2.component.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnInit, inject } from '@angular/core';
22
import { Observable } from 'rxjs';
33

44
import { ApiService } from '../shared/api.service';
55

66
@Component({
7-
selector: 'app-admin',
8-
template: `<p class="alert alert-danger">
7+
selector: 'app-admin',
8+
template: `<p class="alert alert-danger">
99
This is the <strong>🔧 ADMIN 2</strong> component.
1010
It will redirect you to login if needed.
1111
- {{ apiResponse | async }}
1212
</p>`,
13-
standalone: false
13+
standalone: false
1414
})
1515
export class Admin2Component implements OnInit {
16-
apiResponse!: Observable<string>;
16+
private apiService = inject(ApiService);
1717

18-
constructor(private apiService: ApiService) { }
18+
apiResponse!: Observable<string>;
1919

2020
ngOnInit() {
2121
this.apiResponse = this.apiService.getProtectedApiResponse();

src/app/shared/api.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
2-
import { Injectable } from '@angular/core';
2+
import { Injectable, inject } from '@angular/core';
33
import { Observable, of } from 'rxjs';
44
import { catchError, map } from 'rxjs/operators';
55

66
@Injectable()
77
export class ApiService {
8-
constructor(private http: HttpClient) { }
8+
private http = inject(HttpClient);
99

1010
getProtectedApiResponse(): Observable<string> {
1111
return this.http.get<any>('https://demo.duendesoftware.com/api/test')

0 commit comments

Comments
 (0)