Skip to content

Commit

Permalink
Fix the signin process to use a route by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kawazoe committed Jul 28, 2020
1 parent 6c9735b commit ebfde73
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions Westmoor.DowntimePlanner/ClientApp/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import { SignInGuard } from './sign-in-guard.service';
canActivate: [AuthGuard],
data: {role: 'Admin'}
},
{path: 'signin', component: HomeComponent, pathMatch: 'full', canActivate: [SignInGuard]},
{path: 'signout', component: HomeComponent, pathMatch: 'full', canActivate: [SignOutGuard]},
{path: 'oidc-callback', component: HomeComponent, pathMatch: 'full', canActivate: [OidcCallbackGuard]},
{path: 'terms-of-service', component: TermsOfServiceComponent, pathMatch: 'full'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ <h2>Completed downtimes</h2>
<ng-template #guestHeader>
<h1 class="mb-4">Welcome guest!</h1>

<button class="btn btn-primary btn-lg mb-4" routerLink="/sign-in">Sign in</button>
<button class="btn btn-primary btn-lg mb-4" [routerLink]="['/signin']">Sign in</button>

<p>
The Westmoor Downtime Planner is an app design to simplify your D&D downtime experience.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</ng-container>
<ng-template #signedOut>
<li class="nav-item">
<a class="nav-link text-dark" href="#" (click)="signIn()">Sign in</a>
<a class="nav-link text-dark" [routerLink]="['/signin']">Sign in</a>
</li>
</ng-template>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,4 @@ export class NavMenuComponent {
toggle() {
this.isExpanded = !this.isExpanded;
}

signIn() {
this.auth.signIn().subscribe();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
import { AuthService } from './auth.service';
import { switchMap } from 'rxjs/operators';
import { NEVER } from 'rxjs';

@Injectable({
providedIn: 'root'
})
export class SignInGuard implements CanActivate {
constructor(
private auth: AuthService
) {
}

canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
return this.auth.signIn()
.pipe(
switchMap(() => NEVER)
);
}
}

0 comments on commit ebfde73

Please sign in to comment.