Hi all I'm following this https://marmelab.com/admin-on-rest/index.html, for login thing, I'm following https://marmelab.com/admin-on-rest/Authentication.html :
import { AUTH_LOGIN } from 'admin-on-rest';
import restClient from './restClient';
export default (type, params) => {
if (type === AUTH_LOGIN) {
const { username, password } = params;
const request = new Request('http://localhost:9000/login', {
method: 'POST',
headers: new Headers({"Content-Type": "application/json"}),
body: JSON.stringify({ username: username,
password: password})
})
return fetch(request)
.then(response => {
if (response.status < 200 || response.status >= 300) {
throw new Error(response.statusText);
}
return response.json();
})
.then(({ token }) => {
localStorage.setItem('token', token)
});
}
return Promise.resolve();
}
For API I'm using Rails 5.0, when running the code above and debug the params on API side I can't get params body, here is the result :
<ActionController::Parameters {"controller"=>"sessions", "action"=>"create"} permitted: false>
I tried to change sent headers (Content-Type) request to :
...
headers: new Headers({"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"}),
...
And debug the params again on API side, and the result :
<ActionController::Parameters {"{\"username\":\"jhon\",\"password\":\"dow\"}"=>nil, "controller"=>"sessions", "action"=>"create"} permitted: false>
So how to make getting params such :
ActionController::Parameters {"username"=>"jhon", "password"=>"doe", "controller"=>"sessions", "action"=>"create"} permitted: false>