donglu8549 2016-12-12 16:57
浏览 78
已采纳

Symfony + Angular:重定向到登录页面

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.

  • 写回答

1条回答 默认 最新

  • dongmie3987067 2016-12-14 09:21
    关注

    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/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看