Commit d67ca397 authored by David Burke's avatar David Burke

Route to verify-mfa when needed

parent 37a0fc7d
Pipeline #63160297 failed with stages
in 6 minutes and 43 seconds
...@@ -14,12 +14,13 @@ import { ...@@ -14,12 +14,13 @@ import {
UserMustConfirmEmailAction UserMustConfirmEmailAction
} from "../account/account.actions"; } from "../account/account.actions";
import { getToken, IState } from "../app.reducers"; import { getToken, IState } from "../app.reducers";
import { Router } from "@angular/router";
@Injectable() @Injectable()
export class AuthInterceptor implements HttpInterceptor { export class AuthInterceptor implements HttpInterceptor {
token: string | null; token: string | null;
constructor(private store: Store<IState>) { constructor(private store: Store<IState>, private router: Router) {
this.store.pipe(select(getToken)).subscribe(token => (this.token = token)); this.store.pipe(select(getToken)).subscribe(token => (this.token = token));
} }
...@@ -48,6 +49,8 @@ export class AuthInterceptor implements HttpInterceptor { ...@@ -48,6 +49,8 @@ export class AuthInterceptor implements HttpInterceptor {
this.store.dispatch(new LogoutSuccessAction()); this.store.dispatch(new LogoutSuccessAction());
} else if (detail === "User's email is not confirmed.") { } else if (detail === "User's email is not confirmed.") {
this.store.dispatch(new UserMustConfirmEmailAction()); this.store.dispatch(new UserMustConfirmEmailAction());
} else if (detail === "This user requires MFA verification.") {
this.router.navigate(["/account/login/verify-mfa"]);
} }
} }
} }
......
...@@ -5,11 +5,18 @@ import { ...@@ -5,11 +5,18 @@ import {
VerifyMfaSuccess, VerifyMfaSuccess,
VerifyMfaFailure VerifyMfaFailure
} from "./verify-mfa.actions"; } from "./verify-mfa.actions";
import { withLatestFrom, map, exhaustMap, catchError } from "rxjs/operators"; import {
withLatestFrom,
map,
exhaustMap,
catchError,
tap
} from "rxjs/operators";
import { Store, select } from "@ngrx/store"; import { Store, select } from "@ngrx/store";
import { IState, selectVerifyMfaForm } from "../login.reducer"; import { IState, selectVerifyMfaForm } from "../login.reducer";
import { UserService } from "../../account/user"; import { UserService } from "../../account/user";
import { of } from "rxjs"; import { of } from "rxjs";
import { Router } from "@angular/router";
@Injectable() @Injectable()
export class VerifyMFAEffects { export class VerifyMFAEffects {
...@@ -17,18 +24,28 @@ export class VerifyMFAEffects { ...@@ -17,18 +24,28 @@ export class VerifyMFAEffects {
verifyMfa$ = this.actions$.pipe( verifyMfa$ = this.actions$.pipe(
ofType(VerifyMfaActionTypes.VERIFY_MFA), ofType(VerifyMfaActionTypes.VERIFY_MFA),
withLatestFrom(this.store.pipe(select(selectVerifyMfaForm))), withLatestFrom(this.store.pipe(select(selectVerifyMfaForm))),
map(([action, form]) => form.value), map(([action, form]) => form),
exhaustMap(formValue => { exhaustMap(form => {
return this.service.verifyMfa(formValue.otp).pipe( if (form.isValid) {
return this.service.verifyMfa(form.value.otp).pipe(
map(resp => new VerifyMfaSuccess()), map(resp => new VerifyMfaSuccess()),
catchError(err => of(new VerifyMfaFailure())) catchError(err => of(new VerifyMfaFailure()))
); );
}
return of(new VerifyMfaFailure());
}) })
); );
@Effect({ dispatch: false })
verifyMfaSuccess$ = this.actions$.pipe(
ofType(VerifyMfaActionTypes.VERIFY_MFA_SUCCESS),
tap(() => this.router.navigate(["/"]))
);
constructor( constructor(
private actions$: Actions, private actions$: Actions,
private store: Store<IState>, private store: Store<IState>,
private service: UserService private service: UserService,
private router: Router
) {} ) {}
} }
...@@ -66,7 +66,7 @@ export function reducer( ...@@ -66,7 +66,7 @@ export function reducer(
case VerifyMfaActionTypes.VERIFY_MFA_FAILURE: case VerifyMfaActionTypes.VERIFY_MFA_FAILURE:
return { return {
...state, ...state,
errorMessage: "An error occured", errorMessage: "Unable to verify code.",
hasFinished: false, hasFinished: false,
hasStarted: false hasStarted: false
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment