title: How to dispatch api response data into ngrx store from a ngrx effect service
body: <p>I'm struggling to dispatch data to the ngrx store after data is fetched from Api. I actually have a ngrx effect service loginEffect.ts as bellow :</p>
  <pre><code>constructor(private actions$: Actions, private authService: AuthService, private router: Router, private store: Store){}
  
      login$ = createEffect(() =&gt; this.actions$.pipe(
          ofType(loginAction), 
          switchMap(({request}) =&gt; {
              return this.authService.login(request).pipe(
                  map((currentUser: CurrrentUserInterface) =&gt; {
                      return loginSuccessAction({currentUser}) 
                 }),
                 tap(() =&gt; (request.user.username == 'admin') ? this.router.navigate(['dashboard']) : this.router.navigate(['login']) ),
          catchError(() =&gt; {
              return of(loginFailureAction())
          })
              )
          })
  
      ))
  </code></pre>
  <p>It calls the loginService.ts that perfom the api call and login operation like bellow:</p>
  <pre><code>export class loginService {
      constructor(private http: HttpClient, private store: Store){}
    
      login(data: LoginRequestInterface): Observable&lt;CurrrentUserInterface&gt;{
        const url = environment.apiUrl + '/users/login'
        const Option ={ headers: new HttpHeaders({
          'Access-Control-Allow-Origin': '*', 
          'Content-Type': 'application/json',
          'USER_CODE': data.user.USER_CODE})
        };
        return this.http
        .post&lt;authResponseInterface&gt;(url, { username: data.user.username, password: data.user.password }, Option)
        .pipe(map((response: authResponseInterface) =&gt; response.user))
      }
  }
  </code></pre>
  <p>The login is successfull and user is redirected well. But I need to grab the token, userId and user_code from the response yielded by the api, and then dispatch them into the ngrx store in order to use them as params for other api call. But I'm hitting the wall of dispatching such data to the ngrx store. I was good at redux with React app, but not with ngrx. So How can I dispatch the response to ngrx store from the loginEffect.ts or from the loginService.ts?
  I thought that dispatching it inside the loginEffect.ts is a better bet and so I called the</p>
  <blockquote>
  <p>this.store.dispatch(loginSuccessAction({currentUser}))</p>
  </blockquote>
  <p>this but it caused visual studio editor to error out as shown on screenshot:
  <a href="https://i.stack.imgur.com/BQm9O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BQm9O.png" alt="enter image description here" /></a></p>
  <p>In the loginAction.ts I have loginSuccessAction like this:</p>
  <pre><code>export const loginSuccessAction = createAction(
      actionTypes.LOGIN_SUCCES,
      props&lt;{currentUser: CurrrentUserInterface}&gt;()
  )
  </code></pre>
  <p>I even think to write an action to excecute on(loginSuccessAction, ...) in the reducer.ts, but I can't do that because the values that I have to dispatch are only available in the loginEffect.ts or from the loginService.ts. I will be very greatfull for your hepl. Thanks in advance.</p>
  <p><strong>EDITED ACCORDING TO</strong> @MikeOne's <strong>CONTRIBUTION</strong></p>
  <p>When trying to reduce the payload to reducers.ts I did this:</p>
  <pre><code>on(loginSuccessAction, 
      (state: AuthStateInterface): AuthStateInterface =&gt; ({
      ...state,
      USER_CODE:'admin',
      token: 'xrdxgfchgb',
      userId : 63,
  }))
  </code></pre>
  <p>And redux devtool displays the exact data I reduced in there, but those data aren't real data from api, as you can see they are manually set. So my struggle is about how to set the currentUser data fetched from the api response in the reducer. This is the loginSuccessAction that implements the currentUser interface:</p>
  <pre><code>export const loginSuccessAction = createAction(
      actionTypes.LOGIN_SUCCES,
      props&lt;{currentUser: CurrrentUserInterface}&gt;()
  ) 
  </code></pre>
  <p>And this is how logingEffect was supposed to map the api response to currentUser:</p>
  <pre><code>@Injectable()
  export  class loginEffect {
  
      constructor(private actions$: Actions, private authService: AuthService, private router: Router, private store: Store){}
  
      login$ = createEffect(() =&gt; this.actions$.pipe(
          ofType(loginAction), 
          switchMap(({request}) =&gt; {
              console.log(request); return this.authService.login(request).pipe(
                  map((currentUser: CurrrentUserInterface) =&gt; {
                      console.log(currentUser);  return loginSuccessAction({currentUser}) 
                 }),
                 tap(() =&gt; (request.user.username == 'admin') ? this.router.navigate(['dashboard']) : this.router.navigate(['login']) ),
          catchError(() =&gt; {
              return of(loginFailureAction())
          })
              )
          })
  
      ))
  
      
  }
  </code></pre>
  <p>As you can see, I console.log the currentUser in the</p>
  <pre><code>map((currentUser: CurrrentUserInterface) =&gt; {
                          console.log(currentUser);  return loginSuccessAction({currentUser}) 
                     })
  </code></pre>
  <p>But it gives <strong>undefined</strong> in console. Is my &quot;request&quot; properly mapped to currentUser inside the loginEffect.ts ? If so how can I then pass it in reducer.ts . Thank you so much.</p>