0

So, I'm using angular 1.5.9 and Symfony 2.8 in my project. Also FOSUserBundle is in use, but I'm not sure if it's matters.

Currently I need to logout user after 10 minutes inactivity. So, I want to use a solution as described here

And here is a problem I encountered - as long as I using angular and all my requests are asyncronous after this line is executed

$event->setResponse(new RedirectResponse($this->router->generate('fos_user_security_login')));

I'm not being redirected to login page. I was thinking about it but can't figure out what can I do without rewriting my each $http request in order to be able to handle redirect response.

Community
  • 1
  • 1
Majesty
  • 2,097
  • 5
  • 24
  • 55

1 Answers1

1

I think you can use http interceptor to solve this problem. When the user is disconnected if he wants to get protected resource your backend have to return status code 401. So in your interceptor when status code 401 is returned you will redirect your user on the login page.

kris

Doc angular : https://docs.angularjs.org/api/ng/service/$http

Exemple : http://www.webdeveasy.com/interceptors-in-angularjs-and-useful-examples/

Kris
  • 28
  • 3
  • I found another solution http://hackedbychinese.github.io/ng-idle/ before I read your answer, but definately your option is also useful! Thank you! – Majesty Dec 19 '16 at 15:10