I am trying to run a firebase login function from a component in a react app. However, when I call it it isn't firing and I can't figure out why. I double and triple checked my spellings, casings and imports, and I still can't figure it out. Would someone mind taking a look? Thanks! The function I am trying to call is login user and I have commented where it is and also included the function.
//function to-be called
import axios from 'axios';
export const loginuser = (userData) => (dispatch) => {
console.log("loginuser hit"); //this is not firing and neither is my function.
axios
.post('/login', userData)
.then((res) => {
axios.defaults.headers.common['Authorization'] = res.data.token;
console.log(res.data.token);
})
.catch((err) => {
console.log("error in axios login");
});
};
/////class calling the function (in a different file)
import { loginuser } from './redux/userfunctions'
class Login extends Component {
constructor() {
super();
this.state = {
email: '',
password: '',
};
}
handleSubmit = (event) => {
event.preventDefault();
console.log("submit selected");
const userData = {
email: this.state.email,
password: this.state.password
};
loginuser(userData); //this is where I call the function
};
handleChange = (event) => {
this.setState({
[event.target.name]: event.target.value
});
};
render() {
return (
<div className = "sign-in">
<Topbar />
<form onSubmit={this.handleSubmit}>
<input
type = "text"
placeholder="Email"
name="email"
value={this.state.email}
onChange = {this.handleChange}
/>
<input
type = "password"
placeholder= "Password"
name="password"
value={this.state.password}
onChange = {this.handleChange}
/>
<button type = "submit"> Sign In </button>
</form>
</div>
);
}
}
Thanks again!