【发布时间】:2013-03-11 01:31:11
【问题描述】:
我通过 GET 进行了 Devise 身份验证以注销,但无法使用此 Angular.js 代码注销:
$scope.logout = ->
$http.get('/users/sign_out').success ->
#If it does not redirect from 'editor' to 'login' then you haven't actually logged out
$location.path('editor')
Devise 的注销行为似乎是随机的 - 有时会注销,有时不会。
如果我在浏览器的地址栏中输入/users/sign_out,它总是会注销。
好的,我将 Devise 身份验证的注销切换为 POST 请求以消除缓存问题并使用以下 Angular.js 代码:
$scope.logout = ->
$http.post('/users/sign_out').success ->
$location.path('editor')
第一次注销正常,一如既往,但后来我无法注销。
我决定制作自己的方法来看看会发生什么:
match '/logout' => 'api#logout', :via => :post
class ApiController < ApplicationController
before_filter :authenticate_user!
def logout
sign_out
if current_user
puts 'Has not signed out!'
else
puts 'Has signed out!'
end
head :ok
end
end
并检测到sign_out 之后current_user 始终为nil,但随后Angular 应用程序奇迹般地设法访问了ApiController 的其他方法,而current_user 不在那里!
我不明白。好的,让我们假设在注销请求之后(或同时)可能有其他 HTTP 请求,通过身份验证 cookie 并设计重新登录,但是 不应该在 cookie 中传递会话 ID调用sign_out方法后立即过期?!
【问题讨论】:
-
@shicholas:当然
-
Rails cookie 或 ng cookie 怎么样?
标签: ruby-on-rails devise angularjs logout