The action dispatched by 'AuthEffects.googleSignIn' is invalid because all Actions must include a type property

I am encountering the following issues:

  • Effect "AuthEffects.googleSignIn" is triggering an invalid action: [object Object]
  • Uncaught TypeError: Actions must have a type property

You can view the errors below:

https://i.sstatic.net/puY3q.png https://i.sstatic.net/z8bGb.png

How can I fix this issue? The sign-in process works correctly but I need help resolving these errors:

auth.effects.ts

  @Effect()
  googleSignIn = this.actions.pipe(
    ofType(authActions.googleSignIn),
    mergeMap(() =>
      from(this.authService.googleSignIn()).pipe(
        map(() => this.getAuthData,
          catchError(err =>
            of({ error: err.message })
          )
        )
      )
    )
  );

  @Effect()
  getAuthData = this.actions.pipe(
    ofType(authActions.getAuthData),
    mergeMap(() => (
        this.afAuth.authState.pipe(
          map((authData: AuthState) => {
            if (authData) {
              const parsedAuthData: Partial<AuthState> = this.authService.parseAuthData(authData);
              return authActions.authDataRetrieved({ payload: parsedAuthData });
            } else {
              return authActions.authDataNotRetrieved();
            }
          }),
          catchError(error => {
            this.logger.debug(error);
            return of(authActions.authError({ errorMessage: error.message, errorCode: error.code }));
          })
        )
      )
    )
  );

auth.actions.ts

import { createAction, props } from '@ngrx/store';
import { AuthState } from './auth.state';

export const getAuthData = createAction('[Auth] Get authentication data');
export const authDataRetrieved = createAction('[Auth] Authentication data retrieved', props<{payload: Partial<AuthState>}>());
export const authDataNotRetrieved = createAction('[Auth] Authentication data not retrieved');
export const googleSignIn = createAction('[Auth] Google sign-in attempt start');
export const authError = createAction('[Auth] Authentication error occurred', props<{ errorMessage: string, errorCode: string }>());

Answer №1

Make sure to include a return action in your googleSignIn effect like the following:

 getPosts$ = createEffect(() =>
    this.actions$.pipe(
      ofType(PostActions.LoadPosts),
      switchMap(_ => {
        return this.postService
          .getPosts()
          .pipe(
            map(
              (posts: IPost[]) => PostActions.LoadPostsSuccess({ posts }), // add an action here
              catchError(errors => of(PostActions.LoadPostsFail(errors)))
            )
          );
      })
    )
  );

I have identified where the error is occurring, so you can address it accordingly.

@Effect()
  googleSignIn = this.actions.pipe(
    ofType(authActions.googleSignIn),
    mergeMap(() =>
      from(this.authService.googleSignIn()).pipe(
        map(() => this.getAuthData, // remember to return an action at this point
          catchError(err =>
            of({ error: err.message })
          )
        )
      )
    )
  );

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving a nested type based on a particular condition while keeping track of its location

Given an object structure like the one below: type IObject = { id: string, path: string, children?: IObject[] } const tree = [ { id: 'obj1' as const, path: 'path1' as const, children: [ { id: &ap ...

Angular 6 - Defining two components with several modules nested within each other

There are two components, C1 and C2. Each component has its own module file. How can I declare C1 in C2 in Angular 6? // Module 1 @NgModule({ imports: [], exports: [], declarations: [ ComponentX, ComponentY ], providers: [] }) // Module 2 @NgModule ...

Ajax: The requested resource does not have the 'Access-Control-Allow-Origin' header. As a result, access is not permitted from origin 'null'

I recently started learning about ajax and followed a tutorial. However, I encountered an error when trying to run an HTML file along with a linked JavaScript file. Since browsers cannot make requests to file://, I have set up an http-server on port 8080 ...

How to showcase a specific row in a React Native ListView for displaying highscores in a game

Currently, I am working on programming a Highscore Screen for a Quiz Game that utilizes a ListView to display all the players along with their scores. My main goal is to emphasize my own points, since the ListView only shows player IDs and points without a ...

Issue with JS jQuery: The click event on an li element within an expanded ul does not function properly

I have built a basic webpage to explore jQuery. However, there is an issue that arises when I click on the "Button: another one." It seems to interfere with the event of clicking on the li element, causing it to glitch and not respond. Here is the code: JS ...

Unable to retrieve JSON data using jQuery

When working with jQuery to retrieve JSON data, I encountered an issue. After storing the data in a variable named "ajaxResponse," attempting to access specific data points resulted in an error stating that ajaxResponse.blah is not defined. Interestingly, ...

Form that updates the class attribute to 'active'

I have a webpage with 3 list items (<li>) and each has its own onclick() function. One of them is active by default. When a form on the page is submitted, I want it to switch the active class from the default item to one of the other two. How can thi ...

Applying classes dynamically to a custom form component in Angular to tailor its appearance

I am currently working on a custom form component where I need to dynamically apply classes to it. import { Component, forwardRef, Injector } from '@angular/core'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms&apos ...

Encountering a Next.js Strapi error. TypeError: Fetch request unsuccessful

An error occurred during module build: UnhandledSchemeError: The plugin does not support reading from "node:assert" URIs (Unhandled scheme). Webpack natively supports "data:" and "file:" URIs. You might require an extra plugin to handle "node:" URIs. ...

Using jQuery to Verify Matching Objects Based on a Shared Property in Sets

I am in search of a solution using JavaScript or jQuery to ensure that two sets/arrays of objects share the same value for a particular property. In this case, two items share the same guid value across both sets, but some properties differ between them - ...

Python Mechanize: choosing a selection

Can you help me with selecting an option from a select tag? In this particular form, there is only one select tag and no submit button. The purpose is that when an option is chosen, it triggers the javascript function __doPostBack('D1','&ap ...

Node.js is executing the CRON process twice

Within my Node.js application, I have set up a CRON job that runs every day at 10 AM to send push notifications to users. However, I am encountering an issue where two notifications are being sent to the user's device each time the CRON job is trigger ...

Deactivating the Grid and its offspring in React.js MUI

Is it possible to Disable the Grid (MUI Component) and its Children in React js? Additionally, how can we Disable any Container and its items in React js, regardless of the type of children they have? For example: <Grid item disabled // ...

A step-by-step guide on utilizing the reduce function to calculate the overall count of a user's GitHub repositories

I need help finding the total number of repositories for a specific user. Take a look at my code below: Javascript const url = "https://api.github.com/users/oyerohabib/repos?per_page=50"; const fetchRepos = async () => { response = await f ...

Optimize the performance of filtering large GeoJSON files using Ajax in leaflet for the

I am managing four 2MB geoJson files with four different Layers that need to be loaded. Each layer is loaded using the following code: LayerBoon = L.geoJSON.ajax(URL, {pointToLayer:returnBoonMarker, filter:filtertext}); There is also a button click functi ...

Is incorporating CSS advisable in Karma Unit level tests for AngularJS projects?

Imagine your JavaScript code is running some element or position calculations within an AngularJS directive. When testing this JavaScript code, should CSS be included in karma.conf.js? I've noticed that some popular projects have included CSS files. ...

Tips for maintaining the current route in Vue.js after a page refresh while running the Vue.js project in development mode on a specific port?

In my router.ts file, I have defined two routes: export default new Router({ mode: "history", routes: [ { path: "/", component: require("./components/dashboard/Dashboard.vue")}, { path: "/counter", component: require("./components/ ...

What could be the reason for the lack of impact when assigning a [dateClass] in mat-calendar?

I've been trying to customize the appearance of specific days in the mat-calendar component from Angular Material, but I'm having trouble getting it to work. I discovered the dateClass property which seemed like the right solution, but no matter ...

Regular expression in JavaScript that specifically matches numbers formatted in the style of JavaScript

My goal is to develop a javascript regular expression that specifically identifies valid Javascript-style numbers. The requirements entail accommodating an optional minus or plus sign before the number, recognizing the decimal dot, and supporting exponent ...

Convert the date to the standard JavaScript format

After receiving a JSON response with a date property in the format of yyyy-MM-dd, I am aiming to convert it into the default JavaScript format which is: Mon Jun 13 2016 16:35:48 GMT-0400 (Eastern Daylight Time) using Angular.js. I carefully reviewed the d ...