Skip to content

Commit 932ca2e

Browse files
committed
Angular NgRx Course
1 parent d29a704 commit 932ca2e

21 files changed

+17
-445
lines changed

src/app/app.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
<span>Courses</span>
99
</a>
1010

11-
<a mat-list-item routerLink="/login" *ngIf="isLoggedOut$ | async">
11+
<a mat-list-item routerLink="/login">
1212
<mat-icon>account_circle</mat-icon>
1313
<span>Login</span>
1414
</a>
1515

16-
<a mat-list-item (click)="logout()" *ngIf="isLoggedIn$ | async">
16+
<a mat-list-item (click)="logout()">
1717
<mat-icon>exit_to_app</mat-icon>
1818
<span>Logout</span>
1919
</a>

src/app/app.component.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import {Component, OnInit} from '@angular/core';
22
import {select, Store} from "@ngrx/store";
33
import {Observable} from "rxjs";
44
import {map} from 'rxjs/operators';
5-
import {isLoggedIn, isLoggedOut} from './auth/auth.selectors';
65
import {Router} from '@angular/router';
7-
import {logout} from './auth/auth.actions';
8-
import {AppState} from './reducers/reducers';
96

107
@Component({
118
selector: 'app-root',
@@ -14,34 +11,19 @@ import {AppState} from './reducers/reducers';
1411
})
1512
export class AppComponent implements OnInit {
1613

17-
isLoggedIn$: Observable<boolean>;
1814

19-
isLoggedOut$: Observable<boolean>;
20-
21-
22-
constructor(private store: Store<AppState>, private router: Router) {
15+
constructor(private router: Router) {
2316

2417
}
2518

2619
ngOnInit() {
2720

28-
this.isLoggedIn$ = this.store
29-
.pipe(
30-
select(isLoggedIn)
31-
);
3221

33-
this.isLoggedOut$ = this.store
34-
.pipe(
35-
select(isLoggedOut)
36-
);
3722

3823
}
3924

4025
logout() {
4126

42-
this.store.dispatch(logout());
43-
4427
}
4528

46-
4729
}

src/app/app.module.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ import {environment} from '../environments/environment';
1919
import {RouterState, StoreRouterConnectingModule} from '@ngrx/router-store';
2020

2121
import {EffectsModule} from '@ngrx/effects';
22-
import {AuthGuard} from './auth/auth.guard';
2322
import {EntityDataModule} from '@ngrx/data';
24-
import {reducers} from './reducers/reducers';
2523

2624

2725
const routes: Routes = [
2826
{
2927
path: 'courses',
30-
loadChildren: () => import('./courses/courses.module').then(m => m.CoursesModule),
31-
canActivate: [AuthGuard],
28+
loadChildren: () => import('./courses/courses.module').then(m => m.CoursesModule)
3229
},
3330
{
3431
path: '**',
@@ -52,25 +49,7 @@ const routes: Routes = [
5249
MatSidenavModule,
5350
MatListModule,
5451
MatToolbarModule,
55-
AuthModule.forRoot(),
56-
StoreModule.forRoot(reducers, {
57-
runtimeChecks: {
58-
strictStateImmutability: true,
59-
strictActionImmutability: true,
60-
strictActionSerializability: true,
61-
strictStateSerializability: true
62-
}
63-
}),
64-
StoreDevtoolsModule.instrument({
65-
maxAge: 25,
66-
logOnly: environment.production,
67-
}),
68-
EffectsModule.forRoot([]),
69-
StoreRouterConnectingModule.forRoot({
70-
stateKey: 'router',
71-
routerState: RouterState.Minimal,
72-
}),
73-
EntityDataModule.forRoot({})
52+
AuthModule.forRoot()
7453
],
7554
bootstrap: [AppComponent]
7655
})

src/app/auth/action-types.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/app/auth/auth.actions.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/app/auth/auth.effects.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/app/auth/auth.guard.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/app/auth/auth.module.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ import {ReactiveFormsModule} from "@angular/forms";
88
import {MatButtonModule} from "@angular/material/button";
99
import { StoreModule } from '@ngrx/store';
1010
import {AuthService} from "./auth.service";
11-
import * as fromAuth from './auth.reducer';
12-
import {AuthGuard} from './auth.guard';
1311
import { EffectsModule } from '@ngrx/effects';
14-
import { AuthEffects } from './auth.effects';
15-
1612

1713
@NgModule({
1814
imports: [
@@ -22,8 +18,6 @@ import { AuthEffects } from './auth.effects';
2218
MatInputModule,
2319
MatButtonModule,
2420
RouterModule.forChild([{path: '', component: LoginComponent}]),
25-
StoreModule.forFeature('auth', fromAuth.authReducer),
26-
EffectsModule.forFeature([AuthEffects]),
2721

2822
],
2923
declarations: [LoginComponent],
@@ -34,8 +28,7 @@ export class AuthModule {
3428
return {
3529
ngModule: AuthModule,
3630
providers: [
37-
AuthService,
38-
AuthGuard
31+
AuthService
3932
]
4033
}
4134
}

src/app/auth/auth.reducer.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/app/auth/auth.selectors.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/app/auth/login/login.component.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {AuthService} from "../auth.service";
77
import {tap} from "rxjs/operators";
88
import {noop} from "rxjs";
99
import {Router} from "@angular/router";
10-
import {login} from '../auth.actions';
11-
import {AppState} from '../../reducers/reducers';
1210

1311
@Component({
1412
selector: 'login',
@@ -22,8 +20,7 @@ export class LoginComponent implements OnInit {
2220
constructor(
2321
private fb:FormBuilder,
2422
private auth: AuthService,
25-
private router:Router,
26-
private store: Store<AppState>) {
23+
private router:Router) {
2724

2825
this.form = fb.group({
2926
email: ['test@angular-university.io', [Validators.required]],
@@ -38,25 +35,7 @@ export class LoginComponent implements OnInit {
3835

3936
login() {
4037

41-
const val = this.form.value;
42-
43-
this.auth.login(val.email, val.password)
44-
.pipe(
45-
tap(user => {
46-
47-
this.store.dispatch(login({user}));
48-
49-
this.router.navigateByUrl('/courses');
50-
51-
})
52-
)
53-
.subscribe(
54-
noop,
55-
() => alert('Login Failed')
56-
);
57-
58-
5938
}
6039

61-
6240
}
41+

0 commit comments

Comments
 (0)