I did Devise authentication to log out via GET, but could not log out using this Angular.js code:
$scope.logout = ->
$http.get('/users/sign_out').success ->
$location.path('editor')
Identifying the behavior of logging out seems random - sometimes it logs out, sometimes not. And if I type /users/sign_outin the address bar of the browser, it will always log out.
Ok, I switched Devise authentication authentication to a POST request to get rid of caching issues and used the following Angular.js code:
$scope.logout = ->
$http.post('/users/sign_out').success ->
$location.path('editor')
The first time he logged out, as always, but then I could not log out of it.
I decided to make my own method to find out what happens:
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 sign_out?!