0

I have the an Angular JS app (front-end) that communicate to Laravel app (back-end).

I'm stuck in this issue, not always happen but when it does, right after I authenticate some of random requests get 401 (Unauthorized). But if I access the same url using postman it work perfectly.

I'm not sure what show as code, so here's some details that could be valid:

At the Angular JS I have 25 different uri (xhr) to my back-end.

I'm using $httpProvider.interceptors to add the headers:

'Accept': 'application/json',
'Authorization': (AuthService.valid() ? `Bearer ${AuthService.get().token}` : ''),
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'

I'm using JwtAuthenticate at Laravel.

Sorry for low description, if you need some more please tell me.

Pablo
  • 1,953
  • 4
  • 28
  • 57
  • Can you open up Fiddler and see what's being sent when the app fails? http://www.telerik.com/fiddler – Kyle May 02 '16 at 14:47
  • Here's: http://www.jsoneditoronline.org/?id=e14f69eaa1915a551a4a636f94388530 – Pablo May 02 '16 at 14:54
  • Here's another example: https://www.dropbox.com/s/1oftbb7yy4ubtkz/2localhost.har?dl=0 – Pablo May 02 '16 at 15:04

1 Answers1

0

Did you got this sorted out already? I am experiencing an issue that is very similar to this.

I have a Laravel application and when I log in and open a modal that does an ajax call, it will randomly result in a 401 error and I'm logged out. There is no real pattern when this occurs.

Darrin
  • 3
  • 1
  • I did not found an good solution, but I did something. Check this (https://laracasts.com/discuss/channels/laravel/access-denied-for-user-atlocalhost), hope that it can help you. – Pablo May 25 '16 at 17:57
  • This post also helped me figure out my csrf tokens that are need before you send out Ajax. http://stackoverflow.com/questions/33392268/laravel-and-ajax-sporadic-401-errors-in-a-poller – Darrin May 27 '16 at 07:09