Skip to content

Commit 9400af4

Browse files
authored
Add unauthorized page if route requires a logged in user (#7)
1 parent b920539 commit 9400af4

14 files changed

+3365
-97542
lines changed

ClientApp/ClientApp/app/app.module.shared.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { HomeComponent } from './components/home/home.component';
77
import { FetchDataComponent } from './components/fetchdata/fetchdata.component';
88
import { CounterComponent } from './components/counter/counter.component';
99
import { CallbackComponent } from './components/callback/callback.component';
10+
import { UnauthorizedComponent } from './components/unauthorized/unauthorized.component';
1011

1112
import { AuthService } from './components/services/auth.service';
1213
import { GlobalEventsManager } from './components/services/global.events.manager';
@@ -20,13 +21,15 @@ export const sharedConfig: NgModule = {
2021
CounterComponent,
2122
FetchDataComponent,
2223
HomeComponent,
23-
CallbackComponent
24+
CallbackComponent,
25+
UnauthorizedComponent
2426
],
2527
imports: [
2628
RouterModule.forRoot([
2729
{ path: '', redirectTo: 'home', pathMatch: 'full' },
2830
{ path: 'home', component: HomeComponent },
2931
{ path: 'callback', component: CallbackComponent },
32+
{ path: 'unauthorized', component: UnauthorizedComponent },
3033
{ path: 'counter', component: CounterComponent },
3134
{ path: 'fetch-data', component: FetchDataComponent, canActivate:[AuthGuardService] },
3235
{ path: '**', redirectTo: 'home' }

ClientApp/ClientApp/app/components/services/auth-guard.service.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import { AuthService } from './auth.service';
66
@Injectable()
77
export class AuthGuardService implements CanActivate {
88

9-
constructor(private _authService: AuthService, private _router: Router) {
9+
constructor(private authService: AuthService, private router: Router) {
1010
}
1111

1212
canActivate() {
13-
if (this._authService._loggedIn) {
14-
return true;
13+
if (this.authService.loggedIn) {
14+
return true;
1515
}
16-
else{
17-
this._router.navigate(['unauthorized']);
16+
else {
17+
this.router.navigate(['unauthorized']);
1818
}
1919
}
2020
}

0 commit comments

Comments
 (0)