Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

127
Visualizações
Firebase authentication with redux and typescript

I am trying to add authentication to a react website using firebase I currently have this createasyncthunk

    export const signin = createAsyncThunk<
  // Return type of the payload creator
  User | void,
  // First argument to the payload creator
  userData,
  // Types for ThunkAPI
  {
    rejectValue: errorInterface;
  }
>('authentication/signin',  (user, thunkApi) => {
  const { email, password } = user;
  signInWithEmailAndPassword(auth, email, password)
    .then((userCredential) => {
      // Signed in
      const user = userCredential.user;
      return user;
    })
    .catch((error) => {
      console.log(error.message, error.code)
      const errorMessage: errorInterface = { message: error.code };
      return thunkApi.rejectWithValue(errorMessage);
    });
});

the user type is imported from fire base the userData is the following interface to represent credentials used to log in

interface userData {
  email: string;
  password: string;
}

the error interface is the following

interface errorInterface {
  message: string;
}

the authentication slice is this

export const authSlice = createSlice({
  name: 'authentication',
  initialState,
  reducers: {},
  extraReducers: (builder) => {
    builder
      .addCase(signin.pending, (state) => {
        state.status = 'loading';
        state.isAuth = false;
      })
      .addCase(signin.fulfilled, (state, action) => {
        state.status = 'idle';
        state.isAuth = true;
        if (action.payload) {
          state.user = action.payload;
        }
      })
      .addCase(signin.rejected, (state, action) => {
        state.status = 'failed';
        state.isAuth = false;
        if (action.payload) {
          state.message = action.payload.message;
        }
      })
  },
});

The problem is that signin.rejected is never trigered. Even when the catch block runs, rejectwithvalue is not updating the payload. I know the catch block is running because I can see the error in the console. Please help me out, thanks in advance

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda