Skip to content

State is not updating after user logged in. #19

@Tayyab-Shinwari

Description

@Tayyab-Shinwari

When user Logged in the state of User reducer should update with token and email. But in redux devtool action showing user object having email and token property data from server but state is empty. i am following your tutorial so below are codes the progress i have made up to.

code for api.js

import axios from 'axios'

export default {
user:{
login:(credential) => axios.post('/api/auth',{credential}).then(res => res.data.user)
}
}

code for auth.js

import {USER_LOGGED_IN} from '../types'
import api from '../api'

export const userLoggedIn = user => ({
type: USER_LOGGED_IN,
user
});
export const login = (credential) =>(dispatch) => api.user.login(credential).then(user => dispatch(userLoggedIn(user)))

code for reducer user.js

import { USER_LOGGED_IN } from "../types";

const initailState = {
email:'',
token:''
}
export default function user(state = initailState, action = {}) {
switch (action.type) {
case USER_LOGGED_IN:
return action.user;
default:
return state;
}
}

rootreducer code

import { combineReducers } from "redux";

import user from "./reducers/user";
// import books from "./reducers/books";

export default combineReducers({
user:()=>({})

});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions