{"action":"created","issue":{"url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/28","repository_url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth","labels_url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/28/comments","events_url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/28/events","html_url":"https://github.com/lynndylanhurley/devise_token_auth/issues/28","id":42701478,"number":28,"title":"Access to current_user variable?","user":{"login":"kareemgrant","id":1639187,"avatar_url":"https://avatars.githubusercontent.com/u/1639187?v=3","gravatar_id":"","url":"https://api.github.com/users/kareemgrant","html_url":"https://github.com/kareemgrant","followers_url":"https://api.github.com/users/kareemgrant/followers","following_url":"https://api.github.com/users/kareemgrant/following{/other_user}","gists_url":"https://api.github.com/users/kareemgrant/gists{/gist_id}","starred_url":"https://api.github.com/users/kareemgrant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kareemgrant/subscriptions","organizations_url":"https://api.github.com/users/kareemgrant/orgs","repos_url":"https://api.github.com/users/kareemgrant/repos","events_url":"https://api.github.com/users/kareemgrant/events{/privacy}","received_events_url":"https://api.github.com/users/kareemgrant/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2014-09-13T17:47:21Z","updated_at":"2016-03-07T11:23:45Z","closed_at":"2014-09-18T16:24:48Z","body":"I'm using devise_token_auth along with ng-token-auth library for my angular frontend and everything seems to be working well until I try to access the current_user variable to reference the signed in user. I looked at the code and see that you're using @current_user and that works temporarily, but after a few server requests, I lose reference to @current_user and the variable returns nil even though I have successfully logged in.  This prevents me from conducting simple authorization checks (for example: does the current_user belong to the requested account?). Is there something that I'm missing?\r\n\r\nIn a vanilla devise implementation, you would use a ``before_action :authenticate_user!`` in your controller to get access to the devise helper methods (current_user, user_signed_in?, etc). However, that is throwing an error as well. \r\n\r\nThanks!\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/comments/193212269","html_url":"https://github.com/lynndylanhurley/devise_token_auth/issues/28#issuecomment-193212269","issue_url":"https://api.github.com/repos/lynndylanhurley/devise_token_auth/issues/28","id":193212269,"user":{"login":"aarmel-sw","id":17440466,"avatar_url":"https://avatars.githubusercontent.com/u/17440466?v=3","gravatar_id":"","url":"https://api.github.com/users/aarmel-sw","html_url":"https://github.com/aarmel-sw","followers_url":"https://api.github.com/users/aarmel-sw/followers","following_url":"https://api.github.com/users/aarmel-sw/following{/other_user}","gists_url":"https://api.github.com/users/aarmel-sw/gists{/gist_id}","starred_url":"https://api.github.com/users/aarmel-sw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aarmel-sw/subscriptions","organizations_url":"https://api.github.com/users/aarmel-sw/orgs","repos_url":"https://api.github.com/users/aarmel-sw/repos","events_url":"https://api.github.com/users/aarmel-sw/events{/privacy}","received_events_url":"https://api.github.com/users/aarmel-sw/received_events","type":"User","site_admin":false},"created_at":"2016-03-07T11:23:45Z","updated_at":"2016-03-07T11:23:45Z","body":"I had this same issue.  Its how it creates the current user. If you are using the namespace V1. it will actually create current_v1_user instead of current_user.\r\n\r\n(at least with rails 5 beta 3 api option)\r\nIf you *DONT* put 'devise_for :users' below you will have the issue discussed.\r\n\r\nSame goes for the other functions :authenticate_v1_user!\r\n\r\nRails.application.routes.draw do\r\n  devise_for :users\r\n  namespace :v1 do\r\n    mount_devise_token_auth_for 'User', at: 'auth'\r\n    resources :beer \r\n  end\r\nend\r\n\r\nHope that helps.\r\n\r\nGEMFILE\r\n    devise (4.0.0.rc1)\r\n      bcrypt (~> 3.0)\r\n      orm_adapter (~> 0.1)\r\n      railties (>= 4.1.0, < 5.1)\r\n      responders\r\n      warden (~> 1.2.3)\r\n    devise_token_auth (0.1.37)\r\n      devise (> 3.5.2, < 4.1)\r\n      rails (< 6)\r\n "}}