1
import { call ,put} from "redux-saga/effects";
import { setLoading } from "../../component/loader/loaderSlice";
import { handleLogin } from "../../services/loginService";


export function* doUserLogin({payload}){
    const {userName,password} =payload.user
    try {

        const response = yield call(handleLogin(userName,password));
//problem is here , when I am passing a valid user and password its not logging here
        if(response.data){
            console.log('Logge In',response);
        }
        console.log(response.data)
        
    }catch (error) {
// its logging the response when I am getting error from server
        if(error.response){
            console.log(error.response.data)
        }
        
    }

}


authService.js

import axios from 'axios'
import { useSelector, useDispatch } from "react-redux";
export  function handleLogin(userName,password){
    console.log(userName)
    const res= axios.request({
        method:'post',
        url:'http://localhost:8000/api/auth/login',
        data:{
            userName,
            password
        }
    })
    console.log(res);
    return res;
}

authSaga.js

import {takeLatest} from 'redux-saga/effects'
import { handleLogin } from '../../component/login/loginSlice'
import { doUserLogin } from './authSaga'

export function* watcherSaga(){
    yield takeLatest(handleLogin.type,doUserLogin)
}

rootSaga.js

When user is not valid,it is getting logged in error block,but for a valid user its not logging after the yield call(handleLogin(userName,password)) statement. Why its getting stuck there?

secret
  • 237
  • 2
  • 6
  • 2
    Try changing this `yield call(handleLogin(userName,password));` to this `yield call(handleLogin, userName,password);` – Martin Kadlec Jul 04 '21 at 18:15
  • @MartinKadlec thanks a lot, this worked..can you suggest to me some post where I can read more about this. Thanks for the help. – secret Jul 05 '21 at 10:19
  • sure, https://redux-saga.js.org/docs/api/#callfn-args & https://redux-saga.js.org/docs/basics/DeclarativeEffects – Martin Kadlec Jul 05 '21 at 10:29

0 Answers0