kriasoft / aspnet-starter-kit

Cross-platform web development with Visual Studio Code, C#, F#, JavaScript, ASP.NET Core, EF Core, React (ReactJS), Redux, Babel. Single-page application boilerplate.
https://twitter.com/dotnetreact
MIT License
1.16k stars 203 forks source link

Authorization failing on GET method for "data" attribute in "routes.json" #46

Closed andreassavva closed 7 years ago

andreassavva commented 7 years ago

I have an HttpGet method in HomeController which requires authorization with the [Authorize] attribute. I have created a custom authentication like this. I worked it out so it authorizes the user correctly, but the User attribute is null in the GET methods in routes.json:

"path": "/",
"view": "./views/home",
"chunk": "main",
"data": {
  "userStats": "GET /getchartdata/",
  "lastDisposal": "GET /getlastdisposal",
  "totalMonth": "GET /gettotalmonth"
}

Am I doing something wrong? How do I fix this?

andreassavva commented 7 years ago

In the end I've figured it out. In router.js I set credentials: 'same-origin' in the fetch() method. It looks like this:

return fetch(url, { method, credentials: 'same-origin' }).then(resp => resp.json());

According to this, fetch does not send cookies unless explicitly instructed to.