Closed NoMan2000 closed 5 years ago
Details shown above in the network capture. When I don't put in the Authorization Bearer token, it says rest no route found. When I add it to the request, then I get a 403 because the bearer token doesn't match. The route is correct.
I'm using axios as the connecting library.
import axiosLib from 'axios'; const axios = axiosLib.create(); axios.interceptors.request.use( async config => { const localHeaders = { 'X-WP-Nonce': CelestialSettings.nonce }; let jwtObj = {}; const jwt = localStorage.getItem('jwt') || ''; if (jwt) { jwtObj = { Authorization: `Bearer ${jwt}` }; } return { ...config, headers: { ...config.headers, ...localHeaders, ...jwtObj } }; }, error => Promise.reject(error) ); export const createCancelSource = () => axiosLib.CancelToken.source(); export default axios;
And in the submit (React) I have this:
submitLogin = (e: SyntheticEvent<>) => { e.preventDefault(); const {username, password} = this.state; axios.post(`${api}jwt-auth/v1/token`, { username, password }).then((res) => { const {data} = res; localStorage.setItem('jwt', data.token); return data; }).catch((err) => { console.error(err); }); };
I think the route is:
axios.post(`${api}jwt-auth/v1/token?username=${username}&password=${password}`)
Details shown above in the network capture. When I don't put in the Authorization Bearer token, it says rest no route found. When I add it to the request, then I get a 403 because the bearer token doesn't match. The route is correct.
I'm using axios as the connecting library.
And in the submit (React) I have this: