ing
This commit is contained in:
parent
a9eb6863f1
commit
5a3099f3ca
|
@ -25,7 +25,7 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
|||
.select(AuthSelector.select('signined'))
|
||||
.map(signined => {
|
||||
if (!signined) {
|
||||
this.store.dispatch(new AuthStore.SigninRedirect());
|
||||
this.store.dispatch(new AuthStore.SigninRedirect(state.url));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
|||
.select(AuthSelector.select('signined'))
|
||||
.map(signined => {
|
||||
if (!signined) {
|
||||
this.store.dispatch(new AuthStore.SigninRedirect());
|
||||
this.store.dispatch(new AuthStore.SigninRedirect(state.url));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||
import { Store, select } from '@ngrx/store';
|
||||
|
||||
|
@ -16,6 +16,7 @@ export class SigninComponent implements OnInit {
|
|||
error$ = this.store.pipe(select(AuthSelector.select('error')));
|
||||
|
||||
errorMessage: string | null;
|
||||
returnURL: string;
|
||||
|
||||
signinForm: FormGroup;
|
||||
formErrors = {
|
||||
|
@ -24,6 +25,7 @@ export class SigninComponent implements OnInit {
|
|||
};
|
||||
|
||||
constructor(
|
||||
private activatedRoute: ActivatedRoute,
|
||||
private router: Router,
|
||||
private store: Store<AuthStore.State>,
|
||||
private formBuilder: FormBuilder,
|
||||
|
@ -33,6 +35,8 @@ export class SigninComponent implements OnInit {
|
|||
ngOnInit() {
|
||||
this.initForm();
|
||||
|
||||
this.returnURL = this.activatedRoute.snapshot.queryParams['returnURL'] || '/';
|
||||
|
||||
this.pending$.subscribe((pending: boolean) => {
|
||||
if (pending) {
|
||||
this.signinForm.disable();
|
||||
|
@ -79,7 +83,12 @@ export class SigninComponent implements OnInit {
|
|||
this.router.navigateByUrl('/auth/signup');
|
||||
}
|
||||
signin() {
|
||||
this.store.dispatch(new AuthStore.Signin(this.signinForm.value));
|
||||
const signinValue = Object.assign({}, this.signinForm.value);
|
||||
signinValue.options = {
|
||||
returnURL: this.returnURL,
|
||||
};
|
||||
|
||||
this.store.dispatch(new AuthStore.Signin(signinValue));
|
||||
console.log('signin component signin fnc');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ export enum ActionType {
|
|||
export class Signin implements Action {
|
||||
readonly type = ActionType.Signin;
|
||||
|
||||
constructor(public payload: {email: string, password: string}) {}
|
||||
constructor(public payload: {email: string, password: string, options: any}) {}
|
||||
}
|
||||
|
||||
export class SigninSuccess implements Action {
|
||||
|
@ -35,6 +35,7 @@ export class SigninFailure implements Action {
|
|||
|
||||
export class SigninRedirect implements Action {
|
||||
readonly type = ActionType.SigninRedirect;
|
||||
constructor(public payload: string) {}
|
||||
}
|
||||
|
||||
export class Signout implements Action {
|
||||
|
|
|
@ -25,11 +25,13 @@ import {
|
|||
Signin,
|
||||
SigninSuccess,
|
||||
SigninFailure,
|
||||
SigninRedirect,
|
||||
ActionType,
|
||||
} from './auth.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
private _options: any;
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
|
@ -41,7 +43,10 @@ export class Effects {
|
|||
signin$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Signin)
|
||||
.map((action: Signin) => action.payload)
|
||||
.switchMap(payload => this.memberService.signin(payload.email, payload.password))
|
||||
.switchMap(payload => {
|
||||
this._options = payload.options;
|
||||
return this.memberService.signin(payload.email, payload.password);
|
||||
})
|
||||
.map((domainMember: DomainMember) => {
|
||||
return new SigninSuccess(domainMember);
|
||||
})
|
||||
|
@ -52,13 +57,16 @@ export class Effects {
|
|||
@Effect({ dispatch: false })
|
||||
signinSuccess$ = this.actions$
|
||||
.ofType(ActionType.SigninSuccess)
|
||||
.do(() => this.router.navigate(['/']));
|
||||
.do(() => {
|
||||
this.router.navigateByUrl(this._options.returnURL);
|
||||
});
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinRedirect$ = this.actions$
|
||||
.ofType(ActionType.SigninRedirect, ActionType.Signout)
|
||||
.do(authed => {
|
||||
this.router.navigate(['/auth/signin']);
|
||||
.map((action: SigninRedirect) => action.payload)
|
||||
.do(returnURL => {
|
||||
this.router.navigate(['/auth/signin'], {queryParams: {returnURL: returnURL}});
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ export function reducer(state = initialState, action: Actions): State {
|
|||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninSuccess: {
|
||||
case ActionType.SignoutSuccess: {
|
||||
return {
|
||||
...state,
|
||||
signined: false,
|
||||
|
@ -62,7 +62,7 @@ export function reducer(state = initialState, action: Actions): State {
|
|||
};
|
||||
}
|
||||
|
||||
case ActionType.SigninFailure: {
|
||||
case ActionType.SignoutFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
|
|
Loading…
Reference in New Issue
Block a user