When I send request for user registration or login, in 80% cases it works correctly - but in some cases it throws an error like this:
ERROR: invalid input syntax for integer 'foo@bar.com'
It throws this error because request is going to get route and then is interpreted as parameter for getting individual items.
On front-end I'm using axios for requests and there is some actions from redux:
export function userSignupRequest(userData) {
return dispatch => {
return axios.post(`${API_URL}/users`, userData);
}
}
export function login(data) {
return dispatch => {
return axios.post('http://vetguide.co/auth/login', data).then(res => {
const token = res.data.token;
localStorage.setItem('jwtToken', token);
setAuthorizationToken(token);
dispatch(setCurrentUser(jwtDecode(token)));
});
}
}
Also there are authorization headers:
import axios from 'axios';
export default function setAuthorizationToken(token) {
if (token) {
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
} else {
delete axios.defaults.headers.common['Authorization'];
}
}
I can not figure out this error, it's so confusing...
via Mihajlo Jovanović
No comments:
Post a Comment