From 5b012e198cb1455198df136857d0d1a867b777f6 Mon Sep 17 00:00:00 2001 From: Mike Ryan Date: Sat, 28 Mar 2020 20:13:20 -0500 Subject: [PATCH] 12-auth-user-actions --- src/app/auth/actions/auth-user.actions.ts | 7 +++++++ src/app/auth/components/login-page/login-page.component.ts | 7 ++++++- src/app/auth/components/user/user.component.ts | 4 +++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/app/auth/actions/auth-user.actions.ts b/src/app/auth/actions/auth-user.actions.ts index 888d13a..9cca9eb 100644 --- a/src/app/auth/actions/auth-user.actions.ts +++ b/src/app/auth/actions/auth-user.actions.ts @@ -1 +1,8 @@ import { createAction } from "@ngrx/store"; + +export const login = createAction( + "[Auth/User] Login", + (username: string, password: string) => ({ username, password }) +); + +export const logout = createAction("[Auth/User] Logout"); diff --git a/src/app/auth/components/login-page/login-page.component.ts b/src/app/auth/components/login-page/login-page.component.ts index cb69022..43e8ea4 100644 --- a/src/app/auth/components/login-page/login-page.component.ts +++ b/src/app/auth/components/login-page/login-page.component.ts @@ -1,6 +1,7 @@ import { Component } from "@angular/core"; import { Observable, of } from "rxjs"; import { Store } from "@ngrx/store"; +import { State } from "src/app/shared/state"; import { UserModel } from "src/app/shared/models"; import { AuthUserActions } from "../../actions"; import { LoginEvent } from "../login-form"; @@ -18,7 +19,11 @@ export class LoginPageComponent { }); error$: Observable = of(null); + constructor(private store: Store) {} + onLogin($event: LoginEvent) { - // Not Implemented + this.store.dispatch( + AuthUserActions.login($event.username, $event.password) + ); } } diff --git a/src/app/auth/components/user/user.component.ts b/src/app/auth/components/user/user.component.ts index 1d41fcf..8595f63 100644 --- a/src/app/auth/components/user/user.component.ts +++ b/src/app/auth/components/user/user.component.ts @@ -16,7 +16,9 @@ export class UserComponent { username: "NgRx Learner" }); + constructor(private store: Store) {} + onLogout() { - // Not Implemented + this.store.dispatch(AuthUserActions.logout()); } }